STANAANDREY

Tpb57 3/2/2020

Feb 3rd, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int f(int a)
  5. {
  6.     int sum = 0;
  7.     int f = 2, p;
  8.     while (a > 1)
  9.     {
  10.         p = 0;
  11.         while (a % f == 0)
  12.         {
  13.             a /= f;
  14.             p++;
  15.         }
  16.         sum += p;
  17.         f++;
  18.     }
  19.  
  20.     return sum;
  21. }
  22.  
  23. int cntDigs(int x)
  24. {
  25.     int c = 0;
  26.     if (!x)
  27.         return 1;
  28.     while (x)
  29.     {
  30.         x /= 10;
  31.         c++;
  32.     }
  33.  
  34.     return c;
  35. }
  36.  
  37. int toPow(int b, int p)
  38. {
  39.     int r = 1;
  40.     while (p)
  41.     {
  42.         if (p % 2)
  43.             r *= b;
  44.         b *= b;
  45.         p /= 2;
  46.     }
  47.     return r;
  48. }
  49.  
  50. int main()
  51. {
  52.     int n;
  53.     cin >> n;
  54.  
  55.     int cn = n, digs = cntDigs(n), ok = 1;
  56.     do
  57.     {
  58.         if (f(cn) != 1)
  59.             ok = 0;
  60.  
  61.         int rem = cn % 10;
  62.         int div = cn / 10;
  63.         cn = rem * toPow(10, digs - 1) + div;
  64.     }
  65.     while(cn != n && ok);
  66.  
  67.     if (ok)
  68.         cout << "DA";
  69.     else
  70.         cout << "NU";
  71.     return 0;
  72. }
Add Comment
Please, Sign In to add comment