Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:被大数据吓傻了,我还手写pow,然后还是WA

Posted by _CONTINUE at 2017-10-06 12:24:47 on Problem 2109
In Reply To:被大数据吓傻了,我还手写pow,然后还是WA Posted by:201211050121 at 2014-08-31 14:35:21
> 
> import java.util.*;
> import java.math.*;
> public class GG
> {
>     public static void main(String args[])
>     {
>         BigInteger n=BigInteger.ZERO;
>         BigInteger p=BigInteger.ZERO;
>         Scanner cin=new Scanner(System.in);
>         while(cin.hasNext())
>         {
>             n=cin.nextBigInteger();
>             p=cin.nextBigInteger();
>             if(n.compareTo(BigInteger.ONE)==0){
>                 System.out.println(p);
>                 continue;
>             }
>             int l=1,r=2000000010;
>             while(l<r)
>             {
>                 int mid=(l+r)/2;
>                 BigInteger tmp=mypow(BigInteger.valueOf(mid),n);
>                 if(tmp.compareTo(p)==0)
>                 {
>                     System.out.println(mid);
>                     break;
>                 }
>                 else if(tmp.compareTo(p)<0)
>                     l=mid+1;
>                 else
>                     r=mid;
>             }
>         }
>     }
>      public static BigInteger mypow(BigInteger a,BigInteger b){
>         BigInteger ans = BigInteger.ONE;
>         while(b.compareTo(BigInteger.valueOf(1))>=0){
>             //System.out.println(b+">>>>");
>             BigInteger c=b.mod(BigInteger.valueOf(2));
>             if(c.equals(BigInteger.valueOf(1))){
>                 ans = ans.multiply(a);
>                 b = b.subtract(BigInteger.ONE);
>             }
>             b = b.divide(BigInteger.valueOf(2));
>             a = a.multiply(a);
>         }
>         return ans;
>     }
> }
> 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator