标签:数据 include ios pac 因子 des ret ace else
定义函数g(n)为n最大的奇数因子。 求f(n)=g(1)+g(2)+g(3)+…+g(n)。
有多组测试数据(不超过50)。 每组数据一个整数n(0 < n <= 10^8)。
输出对应的f(n),每组数据占一行。
1
2
3
4
5
|
1
2
4
7
|
1
2
3
4
5
|
1
2
6
21
|
#include<iostream> #define LL long long using namespace std; LL n,a; LL fun(const LL x) { if(x==0) return 0; if(x%2==1) return (x+1)*(x+1)/4+fun(x/2); else return x*x/4+fun(x/2); } int main() { while(cin>>n) { cout<<fun(n)<<endl; } return 0; }
标签:数据 include ios pac 因子 des ret ace else
原文地址:http://www.cnblogs.com/Swust-lyon/p/6703399.html