您的位置:首页 > 其它

清华1084,整数拆分

2016-03-10 19:57 316 查看
#include<iostream>
#include<cstdio>

using namespace std;
int nums[1000001];

int main(){
nums[0] = 1;
nums[1] = 1;
nums[2] = 2;
nums[3] = 2;
for(int i = 4;i<1000001;i++){
if(i%2==1)
nums[i] = nums[i-1];//2*i与2*i-1是一样的
else
nums[i] = (nums[i-1]+nums[i/2])%1000000000;//当为偶数时,分为拆项中是否有1,没有1的话则与i/2相同,有1,则把1去除,剩下的与i-1一样
}                                                     //提前进行%运算,防止溢出
int n;
while(scanf("%d",&n)!=EOF){
printf("%d\n",nums
);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: