Advertisement
RaFiN_

java BigInteger and BigDecimal

Jul 6th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. /* java BigInteger and BigDecimal */
  2.  
  3. package myFirst;
  4. import java.math.BigInteger;
  5. import java.math.RoundingMode;
  6. import java.math.BigDecimal;
  7.  
  8. import java.util.*;
  9. public class mathfun {
  10.  
  11.     public static void main(String[] args) {
  12.         // TODO Auto-generated method stub
  13.         Scanner sc = new Scanner(System.in);
  14.         BigInteger num = sc.nextBigInteger();
  15.         BigInteger num2 = sc.nextBigInteger();
  16.         BigInteger Add,Sub,Mul,Div,Mod;
  17.         Add = num.add(num2);
  18.         Sub = num.subtract(num2);
  19.         Mul = num.multiply(num2);
  20.         Div = num.divide(num2);
  21.         Mod = num.mod(num2);
  22.         System.out.println(Add + " "+ Sub + " " + Mul +" " +Div +" "+ Mod );
  23.         BigInteger sum = new BigInteger("0");
  24.         for(int i = 1;i<=10005;i++) {
  25.             BigInteger x = new BigInteger(Integer.toString(i));
  26.             sum =  sum.add(Add.mod(x));
  27.         }
  28.         System.out.println(sum);
  29.        
  30.         if(sum.compareTo(new BigInteger("800"))>=0)System.out.println("YES");
  31.         if(sum.compareTo(Add)>=0)System.out.println("YES");
  32.         for(BigInteger i = BigInteger.ONE;i.compareTo(new BigInteger("10"))<=0;i = i.add(BigInteger.ONE)) {
  33.             System.out.println(i);
  34.            
  35.         }
  36.        
  37.         sum = sum.gcd(Add);
  38.         boolean tr;
  39.         tr = sum.isProbablePrime(1);
  40.         tr = new BigInteger("7").isProbablePrime(1);
  41.  
  42.         System.out.println(tr);
  43.        
  44.         BigDecimal b = new BigDecimal("100");
  45.        
  46.         System.out.println(b.divide(new BigDecimal("3"),5,RoundingMode.CEILING));
  47.  
  48.         System.out.println("Mod Pow = " + a.modPow(b, new BigInteger("10000009"))); // returns a^b mod 10000009
  49.  
  50. System.out.println("Modulus Inverse = " + a.modInverse(b)); //  a^-1 mod b, this throws ArithmeticException - b ≤ 0, or 'a' BigInteger has no multiplicative inverse mod b (that is, this 'a' is not relatively prime to 'b'
  51.  
  52. System.out.println("GCD = " + a.gcd(b)); // finds gcd, how cool is this?
  53.  
  54. System.out.println( a.isProbablePrime(15)? true: false ); // checks if the number is probably prime or not , uses th Miller-Rabin primality test and with certainty of about 15 it is good enough to produce correct results.
  55.  
  56. System.out.println("Next prime after" + a + " is " + a.nextProbablePrime());// Returns the first integer greater than a that is probably prime.
  57.        
  58.        
  59.        
  60.        
  61.  
  62.     }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement