- #include <bits/stdc++.h>
- using namespace std;
- int cnt(long long n)
- {
- int temp=0;
- for(long long i=1; i<=n; i*=2)
- {
- if(n & i)
- temp++;
- }
- return temp;
- }
- /*
- void bin(int n){
- int mask = 1;
- for(int i = 31; i>= 0; i--){
- mask = 1<<i;
- if(mask&n) cout<<"1";
- else cout<<"0";
- }
- cout<<endl;
- }
- */
- int main()
- {
- int t,cases=0;
- scanf("%d",&t);
- while(t--)
- {
- long long n,ans;
- scanf("%lld",&n);
- //bin(n);
- for(long long i=0; i<32; i++){
- int mask = 1<<i;
- if(n & mask){
- //cout<<" ans, n, i = , "<<ans<<" "<<n<<" "<<i<<" "<<endl;
- ans=n+mask;
- //bin(ans);
- //cout<<" ans, n, i = , "<<ans<<" "<<n<<" "<<i<<" "<<endl;
- break;
- }
- }
- int diff=cnt(n)-cnt(ans);
- for(int i=0; i<diff; i++)
- ans+=(1<<i);
- printf("Case %d: %lld\n",++cases,ans);
- }
- return 0;
- }
Friday 28 July 2017
Lightoj 1042 - Secret Origins
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
Problem link: Problem Analysis: It is actually a basic Bisection problem , as we can see here we can not actually find a formula fo...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
No comments:
Post a Comment