http://acm.nyist.net/JudgeOnline/problem.php?pid=954
循环的可怕之处!!
所有的测试数据结果完全一样。只是超时!!TimeLimitExceeded
#include<stdio.h> #include<stdlib.h> #include<iostream> using namespace std; void init() { freopen("a.in","r",stdin); freopen("a.out","w",stdout); } int main() { int n; int i,k; //init(); while (cin>>n) { k = 1; for(i = 2;i<=n;i*=2) { k += n/i; } cout<<k<<endl; } return 0; } /* #include<stdio.h> #include<stdlib.h> #include<iostream> using namespace std; int main() { int n; int i,k,j; while (scanf("%d",&n)!=EOF) { k = 1; for(i = 1;i<=n;i++) { if (0==i%2) { k++; j = i/2; while (j!=0) { if (0==j%2) { k++; j = j/2; } else break; } } } printf("%d ",k); } return 0; } */