Light OJ 1042

This is the tale of Zephyr, the greatest time traveler theworld will never know. Even those who are aware of Zephyr's existence know verylittle about her. For example, no one has any clue as to which time period sheis originally from.

But we do know the story of the first time she set out tochart her own path in the time stream. Zephyr had just finished building hertime machine which she named - "Dokhina Batash". She was making thefinal adjustments for her first trip when she noticed that a vital program wasnot working correctly. The program was supposed to take a number N, andfind what Zephyr called its Onoroy value.

The Onoroy value of an integer N is the number of onesin its binary representation. For example, the number 13 (11012) hasan Onoroy value of 3. Needless to say, this was an easy problem for the greatmind of Zephyr. She solved it quickly, and was on her way.

You are now given a similar task. Find the first numberafter N which has the same Onoroy value as N.

Input

Input starts with an integer T (≤ 65),denoting the number of test cases.

Each case begins with an integer N (1 ≤ N ≤109).

Output

For each case of input you have to print the case number andthe desired result.

Sample Input

Output for Sample Input

5

23

14232

391

7

8

Case 1: 27

Case 2: 14241

Case 3: 395

Case 4: 11

Case 5: 16


上来直接暴力做:#include<stdio.h>
int value(int n)
{    int b,v=0;
    while(n!=0)
    {b=n%2;
    n/=2;
    v+=b;}
return v;

}
int main()
{
    int t,n,a,i=1,m;
    scanf("%d",&t);
    while(t--)
    {scanf("%d",&n);
    a=n+1;m=value(n);
    while(1)
    {if(value(a)==m)break;
    else
        a++;}
    printf("Case %d: %d\n",i,a);
    i++;
    }
    return 0;
}

TLE;

再问人。。。从二进制下手,编了半天出不来啊,烦!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值