Advertisement
tuki2501

c11prime.cpp

Nov 8th, 2021
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. ll binpow(ll a, ll b) {
  7.   if (b == 0) return 1;
  8.   ll t = binpow(a, b / 2);
  9.   if (t == -1 || t > 1e9) return -1;
  10.   t = t * t;
  11.   if (b % 2) return t * a;
  12.   return t;
  13. }
  14.  
  15. bool isPrime(ll x) {
  16.   if (x <= 1) return false;
  17.   for (ll i = 2; i * i <= x; i++) {
  18.     if (x % i == 0) return false;
  19.   }
  20.   return true;
  21. }
  22.  
  23. int main() {
  24.   ll n; cin >> n;
  25.   for (ll i = 2; i <= 60; i++) {
  26.     ll t = exp(log(n) / i);
  27.     for (ll j = max(0ll, t - 10); j <= t + 10; j++) {
  28.       if (binpow(j, i) == n && isPrime(j)) {
  29.         cout << j << ' ' << i << '\n';
  30.         return 0;
  31.       }
  32.     }
  33.   }
  34.   cout << 0 << '\n';
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement