Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- long long binpow(long long x, long long y)
- {
- if (y == 0) return 1;
- if (y % 2) return x*binpow(x,y-1);
- long long res = binpow(x,y/2);
- res*=res;
- return res;
- }
- long long func (long long n, long long k)
- {
- long long res = 1;
- while (binpow(res,k) < n) res++;
- if (binpow(-res,k) == n) return -res;
- if (binpow(res,k) == n) return res;
- return 0;
- }
- long long main()
- {
- int n,k;
- scanf("%lld %lld", &n, &k);
- printf("%lld", func(n,k));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement