Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
被大数据吓傻了,我还手写pow,然后还是WAimport 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator