标签:华为入职练习 华为oj
#include <iostream> #include <stdio.h> #define MAX 1000000000 using namespace std; int main() { int N =0 ; while (EOF != scanf("%d", &N)) { if (N < 1 || N > 1000000) { cout<<"-1"<<endl; } long long *num = new long long [N +1]; memset(num, 0, sizeof(long long) * (N+1)); num[0] = 1; num[1] = 1; num[2] = 2; for (int i = 3; i <= N; ++i) { if (0 == i%2) //为偶数 { num[i] = (num[i-1] +num[i/2]) %MAX;//把偶数的二进制看成有1的部分,和没有1的部分 } else //为奇数 { num[i] = num[i-1]; } } cout<<num[N]<<endl; delete [] num; } return 0; }
标签:华为入职练习 华为oj
原文地址:http://blog.csdn.net/xiaohanstu/article/details/42389883