Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. long long binpow(long long x, long long y)
  6. {
  7.     if (y == 0) return 1;
  8.  
  9.     if (y % 2) return x*binpow(x,y-1);
  10.  
  11.     long long res = binpow(x,y/2);
  12.     res*=res;
  13.     return res;
  14. }
  15. long long func (long long n, long long k)
  16. {
  17.     long long res = 1;
  18.     while (binpow(res,k) < n) res++;
  19.  
  20.     if (binpow(-res,k) == n) return -res;
  21.    
  22.     if (binpow(res,k) == n) return res;
  23.  
  24.     return 0;
  25.    
  26. }
  27. long long main()
  28. {
  29.     int n,k;
  30.     scanf("%lld %lld", &n, &k);
  31.     printf("%lld", func(n,k));
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement