Advertisement
wrench786

Secret Origins - TLE (LOJ)

Jan 10th, 2021
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define wrench786 ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  3. #define ll long long
  4. #define PI (acos(-1.0))
  5. #define LIMIT 1000000000
  6. using namespace std;
  7.  
  8. int BinOne(ll int n){
  9.     int ans =0;
  10.     while(n!=0){
  11.         if(n&1) ans++;
  12.         n>>=1;
  13.     }
  14.     return ans;
  15. }
  16.  
  17. int main(){
  18.     wrench786
  19.  
  20. #ifndef ONLINE_JUDGE
  21.     clock_t tStart = clock();
  22.     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  23. #endif
  24.  
  25.     int tc,cases=0;
  26.     cin>>tc;
  27.     while(tc--){
  28.         cout<<"Case "<<++cases<<": ";
  29.         ll int n,i,ans1=0,ans2=0;
  30.         cin>>n;
  31.         ans1 = BinOne(n);
  32.         for(i=n+1;;i++){
  33.             ans2 = BinOne(i);
  34.             if(ans1==ans2){
  35.                 cout<<i<<endl;
  36.                 break;
  37.             }
  38.         }
  39.     }
  40.  
  41. #ifndef ONLINE_JUDGE
  42.     fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  43. #endif
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement