Advertisement
ivnikkk

Untitled

Mar 9th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC optimize("unroll-loops")
  3. #pragma GCC target("avx2")
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #define debug(l) cerr<<" smotri huinyi : "<<#l<<' '<<l<<'\n';
  6. #include "bits/stdc++.h"
  7. //#include "geometry.h"
  8. //#include "data_structure.h"
  9. using namespace std;
  10. using namespace chrono;
  11. #define all(cnt) cnt.begin(), cnt.end()
  12. #define allr(cnt) cnt.rbegin(), cnt.rend()
  13. #define sqrt(l) sqrtl(l)
  14. mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
  15. typedef long long ll;
  16. typedef long double ld;
  17. signed main() {
  18. #ifdef _DEBUG
  19.     freopen("input.txt", "r", stdin);
  20.     freopen("output.txt", "w", stdout);
  21. #endif
  22.     ios_base::sync_with_stdio(false);
  23.     cin.tie(nullptr);
  24.     ll a, b;
  25.     cin >> a >> b;
  26.     vector<ll> ans;
  27.     for (ll i = a; i <= b; i++) {
  28.         string s = to_string(i);
  29.         bool ok = true;
  30.         ll sum = 0;
  31.         for (ll j = 0; j < (ll)s.size(); j++) {
  32.             ll ch = s[j] - '0';
  33.             sum += pow(ch, s.size());
  34.         }
  35.         ok = sum == i;
  36.         if (ok) {
  37.             ans.push_back(i);
  38.         }
  39.     }
  40.     if (ans.empty()) {
  41.         cout << -1 << endl;
  42.         return 0;
  43.     }
  44.     for (ll& i : ans) {
  45.         cout << i << ' ';
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement