2539:Division
keyword
整数 多倍長 Java
概要
a,b,t(0
import java.util.*; import java.math.*; class Main { private static BigInteger solve(int t, int a, int b){ if(t==1 || a % b != 0) return BigInteger.ZERO; if(a==b) return BigInteger.ONE; if(Math.log10(t)*(a-b) > 105) return BigInteger.ZERO; BigInteger T = new BigInteger(Integer.toString(t)); BigInteger ret = (T.pow(a).subtract(BigInteger.ONE)).divide(T.pow(b).subtract(BigInteger.ONE)); if(ret.toString().length() >= 100) return BigInteger.ZERO; return ret; } public static void main(String args[]){ Scanner in = new Scanner(System.in); while(in.hasNextInt()){ int t = in.nextInt(), a = in.nextInt(), b = in.nextInt(); BigInteger ans = solve(t,a,b); if(ans.equals(BigInteger.ZERO)) System.out.printf( "(%d^%d-1)/(%d^%d-1) is not an " + "integer with less than 100 digits.\n", t,a,t,b); else System.out.printf( "(%d^%d-1)/(%d^%d-1) %d\n", t,a,t,b,ans); } } }