Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int f(int a)
- {
- int sum = 0;
- int f = 2, p;
- while (a > 1)
- {
- p = 0;
- while (a % f == 0)
- {
- a /= f;
- p++;
- }
- sum += p;
- f++;
- }
- return sum;
- }
- int cntDigs(int x)
- {
- int c = 0;
- if (!x)
- return 1;
- while (x)
- {
- x /= 10;
- c++;
- }
- return c;
- }
- int toPow(int b, int p)
- {
- int r = 1;
- while (p)
- {
- if (p % 2)
- r *= b;
- b *= b;
- p /= 2;
- }
- return r;
- }
- int main()
- {
- int n;
- cin >> n;
- int cn = n, digs = cntDigs(n), ok = 1;
- do
- {
- if (f(cn) != 1)
- ok = 0;
- int rem = cn % 10;
- int div = cn / 10;
- cn = rem * toPow(10, digs - 1) + div;
- }
- while(cn != n && ok);
- if (ok)
- cout << "DA";
- else
- cout << "NU";
- return 0;
- }
Add Comment
Please, Sign In to add comment