Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- int t, a, b;
- BigInteger rs, tt, ta, tb, m, n;
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()) {
- t = sc.nextInt();
- a = sc.nextInt();
- b = sc.nextInt();
- if (t==1 | a < b | a % b != 0 | (a-b)*Math.log10(t)>99) {
- System.out.println("(" + t + "^" + a + "-1)/(" + t + "^" + b + "-1) is not an integer with less than 100 digits.");
- }
- else if(a==b){
- System.out.println("(" + t + "^" + a + "-1)/(" + t + "^" + b + "-1) 1");
- }
- else {
- tt = BigInteger.valueOf(t);
- ta = BigInteger.valueOf(a);
- tb = BigInteger.valueOf(b);
- m = tt.pow((int) a);
- n = tt.pow((int) b);
- m = m.subtract(BigInteger.ONE);
- n = n.subtract(BigInteger.ONE);
- rs = m.divide(n);
- System.out.println("(" + t + "^" + a + "-1)/(" + t + "^" + b + "-1) "+rs);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment