Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
3s | 8192K | 827 | 306 | Standard |
2 5 10 0
1 3 8
Problem Source: skywind
This problem is used for contest: 33
这个题目主要是想到将数字转化为二进制码的形式,然后对每个1计算进位次数。。。。
#include<stdio.h>
int mul(int n)
{
int sum=0;
for(int i=0;i<n;i++)
{
sum+=(1<<i);
}
return sum;
}
int main()
{
int n;
while(scanf("%d",&n),n)
{
int count=0;
int sum=0;
while(n>0)
{
n=n>>1;
count++;
if(n%2==1)
{
sum+=mul(count);
}
}
printf("%d\n",sum);
}
return 0;
}