Pabon_SEC

Division

Feb 17th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.28 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         int t, a, b;
  9.  
  10.         BigInteger rs, tt, ta, tb, m, n;
  11.  
  12.         Scanner sc = new Scanner(System.in);
  13.  
  14.         while (sc.hasNext()) {
  15.  
  16.             t = sc.nextInt();
  17.             a = sc.nextInt();
  18.             b = sc.nextInt();
  19.            
  20.             if (t==1 | a < b | a % b != 0 | (a-b)*Math.log10(t)>99) {
  21.  
  22.                 System.out.println("(" + t + "^" + a + "-1)/(" + t + "^" + b + "-1) is not an integer with less than 100 digits.");
  23.  
  24.             }
  25.            
  26.             else if(a==b){
  27.                
  28.                 System.out.println("(" + t + "^" + a + "-1)/(" + t + "^" + b + "-1) 1");
  29.          
  30.             }
  31.          
  32.             else {
  33.  
  34.                 tt = BigInteger.valueOf(t);
  35.                 ta = BigInteger.valueOf(a);
  36.                 tb = BigInteger.valueOf(b);
  37.  
  38.                 m = tt.pow((int) a);
  39.                 n = tt.pow((int) b);
  40.  
  41.                 m = m.subtract(BigInteger.ONE);
  42.  
  43.                 n = n.subtract(BigInteger.ONE);
  44.  
  45.                 rs = m.divide(n);
  46.                
  47.                 System.out.println("(" + t + "^" + a + "-1)/(" + t + "^" + b + "-1) "+rs);
  48.  
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment