uva10622 Perfect p-th Powers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.