wrench786

Secret Origins - bruteforce

Feb 2nd, 2021
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 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. #define pb push_back
  7. #define dot(x) fixed<<setprecision(x)
  8. using namespace std;
  9.  
  10. int BinOne(ll int n){
  11.     int ans =0;
  12.     while(n!=0){
  13.         if(n&1) ans++;
  14.         n>>=1;
  15.     }
  16.     return ans;
  17. }
  18.  
  19. string solve(int n){
  20.     string str;
  21.     while(n!=0){
  22.         if(n&1) str.pb('1');
  23.         else str.pb('0');
  24.         n>>=1;
  25.     }
  26.     reverse(str.begin(),str.end());
  27.     return str;
  28. }
  29.  
  30. int main(){
  31.     wrench786
  32.  
  33. #ifndef ONLINE_JUDGE
  34.     clock_t tStart = clock();
  35.     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  36. #endif
  37.     int j;
  38.     for(j=1;j<=32;j++){
  39.         ll int n,i,ans1=0,ans2=0;
  40.         ans1 = BinOne(j);
  41.         for(i=j+1;;i++){
  42.             ans2 = BinOne(i);
  43.             if(ans1==ans2){
  44.                 string str1 = solve(j);
  45.                 string str2 = solve(i);
  46.                 cout<<j<<" = "<<str1<<" "<<str2<<" = "<<i<<endl;
  47.                 break;
  48.             }
  49.         }
  50.     }
  51.  
  52. #ifndef ONLINE_JUDGE
  53.     fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  54. #endif
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment