HDU 5170 GTY's math problem 水题
题目链接:
hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5170
bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=567&pid=1001
题解:
先用java大数幂写的,t了
1 import java.util.*; 2 import java.math.*; 3 public class Main { 4 public static void main(String args[]){ 5 Scanner cin = new Scanner(System.in); 6 BigInteger a,c; 7 int b,d; 8 9 while(cin.hasNext()){ 10 a=cin.nextBigInteger(); 11 b=cin.nextInt(); 12 c=cin.nextBigInteger(); 13 d=cin.nextInt(); 14 15 a=a.pow(b); 16 c=c.pow(d); 17 //四则运算 18 19 if(a.compareTo(c)>0) System.out.println(">"); 20 else if(a.compareTo(c)<0) System.out.println("<"); 21 else System.out.println("="); 22 } 23 } 24 }
然后用java写了一个大数的快速幂,同t
1 import java.util.*; 2 import java.math.*; 3 public class Main { 4 public static BigInteger solve(BigInteger a,int n){ 5 BigInteger ret=BigInteger.ONE; 6 // System.out.println("a:"+a.toString()); 7 while(n>0){ 8 if((n&1)>0){ 9 // System.out.println("fuck!"); 10 ret=ret.multiply(a); 11 } 12 a=a.multiply(a); 13 n/=2; 14 } 15 // System.out.println("ret!"+ret.toString()); 16 return ret; 17 } 18 public static void main(String args[]){ 19 Scanner cin = new Scanner(System.in); 20 BigInteger a,c; 21 int b,d; 22 23 while(cin.hasNext()){ 24 a=cin.nextBigInteger(); 25 b=cin.nextInt(); 26 c=cin.nextBigInteger(); 27 d=cin.nextInt(); 28 29 a=solve(a,b); 30 c=solve(c,d); 31 32 // System.out.println(a.toString()); 33 // System.out.println(c.toString()); 34 //四则运算 35 36 if(a.compareTo(c)>0) System.out.println(">"); 37 else if(a.compareTo(c)<0) System.out.println("<"); 38 else System.out.println("="); 39 } 40 } 41 }