Advertisement
Korotkodul

ege_N5

Mar 30th, 2023 (edited)
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <set>
  7.  
  8. using namespace std;
  9. #define ll long long
  10. bool sh = 0;
  11.  
  12. string bin(ll x) {
  13.     string s;
  14.     while (x > 0) {
  15.         s += x % 2 + '0';
  16.         x /= 2;
  17.     }
  18.     reverse(s.begin(), s.end());
  19.     return s;
  20. }
  21.  
  22. ll dec(string s) {
  23.     int n = s.size();
  24.     reverse(s.begin(), s.end());
  25.     ll res = 0;
  26.     for (int i = 0; i < n; ++i) {
  27.         res += (ll)( ((int)s[i] - (int)'0') * pow(2, i) );
  28.     }
  29.     return res;
  30. }
  31.  
  32. ll iter(int x) {
  33.     if (sh) {
  34.         cout << "ITERATION\n";
  35.     }
  36.     string sx = to_string(x);
  37.     ll sum_dig = 0;
  38.     for (char k: sx) {
  39.         sum_dig += (int)k - (int)'0';
  40.     }
  41.     string binsx = bin(x);
  42.     if (sum_dig % 2 == 1) {
  43.         binsx += '1';
  44.     } else {
  45.         binsx += '0';
  46.     }
  47.     ll res = dec(binsx);
  48.     if (sh) {
  49.         cout << "x = " << x << "\n";
  50.         cout << "sx = " << sx << "\n";
  51.         cout << "sum_dig = " << sum_dig << "\n";
  52.         cout << "binsx = " << binsx << "\n";
  53.         cout << "\n";
  54.     }
  55.     return res;
  56. }
  57.  
  58. int f(int x) {
  59.     for (int i = 0 ;i < 3; ++i) {
  60.         x = iter(x);
  61.         if (sh) {
  62.             cout << "i = " << i << "\n";
  63.             cout << "x = " << x << "\n";
  64.             cout << "\n";
  65.         }
  66.     }
  67.     return x;
  68. }
  69.  
  70.  
  71. int main()
  72. {
  73.     sh = 0;
  74.     //cout << f(17);
  75.     ll l = 123456789, r = 1987654321;
  76.     set <ll> var;
  77.     for (ll i = l; i <= r; ++i) {
  78.         ll k = f(i);
  79.         var.insert(k);
  80.     }
  81.     int ans = var.size();
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement