留坑(p.343)
完全不知道哪里有问题qwq
从31向下开始枚举p,二分找存在性,或者数学函数什么的也兹辞啊
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream> using namespace std; void setIO(const string& s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template<typename Q> Q read(Q& x) {
static char c, f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x;
return x;
}
template<typename Q> Q read() {
static Q x; read(x); return x;
} typedef long long LL; LL qpow(LL a, LL b, LL Lim = ~0ull >> ) {
for(LL c = ; ; a *= a) {
if(b & ) c *= a;
if(!(b >>= )) return c;
if(c > Lim || a > Lim) return -;
}
} bool exist(LL x, LL p) {
int l = , r = ~0u >> ;
while(l <= r) {
int mid = l + (r - l) / ;
LL res = qpow(mid, p, x);
if(res == x) return ;
else if(res == - || res > x) r = mid - ;
else l = mid + ;
}
return ;
} int solve(LL n) {
if(n == ) return ;
int sign = ;
if(n < ) sign = -, n = -n;
for(int p = ; p >= ; p -= (sign > ? : )) {
if(exist(n, p)) return p;
}
return ;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n;
while(read(n)) {
printf("%d\n", solve(n));
} return ;
}