Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <set>
- using namespace std;
- #define ll long long
- bool sh = 0;
- string bin(ll x) {
- string s;
- while (x > 0) {
- s += x % 2 + '0';
- x /= 2;
- }
- reverse(s.begin(), s.end());
- return s;
- }
- ll dec(string s) {
- int n = s.size();
- reverse(s.begin(), s.end());
- ll res = 0;
- for (int i = 0; i < n; ++i) {
- res += (ll)( ((int)s[i] - (int)'0') * pow(2, i) );
- }
- return res;
- }
- ll iter(int x) {
- if (sh) {
- cout << "ITERATION\n";
- }
- string sx = to_string(x);
- ll sum_dig = 0;
- for (char k: sx) {
- sum_dig += (int)k - (int)'0';
- }
- string binsx = bin(x);
- if (sum_dig % 2 == 1) {
- binsx += '1';
- } else {
- binsx += '0';
- }
- ll res = dec(binsx);
- if (sh) {
- cout << "x = " << x << "\n";
- cout << "sx = " << sx << "\n";
- cout << "sum_dig = " << sum_dig << "\n";
- cout << "binsx = " << binsx << "\n";
- cout << "\n";
- }
- return res;
- }
- int f(int x) {
- for (int i = 0 ;i < 3; ++i) {
- x = iter(x);
- if (sh) {
- cout << "i = " << i << "\n";
- cout << "x = " << x << "\n";
- cout << "\n";
- }
- }
- return x;
- }
- int main()
- {
- sh = 0;
- //cout << f(17);
- ll l = 123456789, r = 1987654321;
- set <ll> var;
- for (ll i = l; i <= r; ++i) {
- ll k = f(i);
- var.insert(k);
- }
- int ans = var.size();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement