fork download
  1. #include <bits/stdc++.h>
  2. #include <chrono>
  3. #define int long long
  4. #define all(x) x.begin(), x.end()
  5. #define f1(i, n) for(int i=1;i<=n;++i)
  6. using namespace std;
  7. using namespace chrono;
  8.  
  9. const int maxn = 1e6 + 5;
  10. const int MOD = 987654321012345;
  11.  
  12. int count_digit(int n) {
  13. int count = 0;
  14. while (n != 0) {
  15. n /= 10;
  16. count++;
  17. }
  18. return count;
  19. }
  20.  
  21. int luythua[20];
  22. void gen(int n) { // tiền xử lí lũy thua
  23. int digits = count_digit(n);
  24. luythua[0] = 0; luythua[1] = 1;
  25. for (int i = 2; i <= 9; ++i) {
  26. luythua[i] = pow(i, digits);
  27. }
  28. }
  29.  
  30. bool check_Armstrong(int n) {
  31. int sum = 0, digits = count_digit(n), num = n;
  32. gen(n);
  33. while (n != 0) {
  34. sum += luythua[n % 10];
  35. n /= 10;
  36. }
  37. return sum == num;
  38. }
  39. main() {
  40. ios::sync_with_stdio(false);
  41. cin.tie(nullptr);
  42. cout.tie(nullptr);
  43.  
  44. int n;
  45. cin >> n;
  46. cout << (check_Armstrong(n) ? "true" : "false");
  47.  
  48. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
false