Stay Pit (p.343)
I have no idea where the problem is QWQ
From 31 down to enumerate p, binary find existence, or math function what are you doing?
1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <algorithm>5#include <iostream>6 7 using namespacestd;8 9 voidSetio (Const string&s) {TenFreopen ((S +". in"). C_STR (),"R", stdin); OneFreopen ((S +". out"). C_STR (),"W", stdout); A } -Template<typename q> Q Read (q&x) { - Static Charc, F; the for(f =0; c = GetChar (),!isdigit (c); )if(c = ='-') F =1; - for(x =0; IsDigit (c); c = GetChar ()) x = x *Ten+ C-'0'; - if(f) x =-x; - returnx; + } -Template<typename q>Q Read () { + StaticQ x; Read (x);returnx; A } at -typedefLong LongLL; - -ll Qpow (ll A, ll B, ll Lim = ~0ull >>1) { - for(LL C =1; ; A *=a) { - if(B &1) C *=A; in if(! (b >>=1))returnC; - if(C > Lim | | a > Lim)return-1; to } + } - the BOOLexist (ll X, ll p) { * intL =0, R = ~0u>>1; $ while(L <=r) {Panax Notoginseng intMID = L + (r-l)/2; -LL res =Qpow (Mid, p, x); the if(res = = x)return 1; + Else if(res = =-1|| Res > x) r = mid-1; A ElseL = mid +1; the } + return 0; - } $ $ intSolve (LL N) { - if(n = =1)return 1; - intSign =1; the if(N <0) Sign =-1, n =-N; - for(intp = to; P >=2; P-= (sign >0?1:2)) {Wuyi if(Exist (n, p))returnp; the } - return 1; Wu } - About intMain () { $ #ifdef DEBUG -Freopen ("In.txt","R", stdin); -Freopen ("OUT.txt","W", stdout); - #endif A intN; + while(Read (n)) { theprintf"%d\n", Solve (n)); - } $ the return 0; the}
View Code
uva10622 Perfect p-th Powers