Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* java BigInteger and BigDecimal */
- package myFirst;
- import java.math.BigInteger;
- import java.math.RoundingMode;
- import java.math.BigDecimal;
- import java.util.*;
- public class mathfun {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner sc = new Scanner(System.in);
- BigInteger num = sc.nextBigInteger();
- BigInteger num2 = sc.nextBigInteger();
- BigInteger Add,Sub,Mul,Div,Mod;
- Add = num.add(num2);
- Sub = num.subtract(num2);
- Mul = num.multiply(num2);
- Div = num.divide(num2);
- Mod = num.mod(num2);
- System.out.println(Add + " "+ Sub + " " + Mul +" " +Div +" "+ Mod );
- BigInteger sum = new BigInteger("0");
- for(int i = 1;i<=10005;i++) {
- BigInteger x = new BigInteger(Integer.toString(i));
- sum = sum.add(Add.mod(x));
- }
- System.out.println(sum);
- if(sum.compareTo(new BigInteger("800"))>=0)System.out.println("YES");
- if(sum.compareTo(Add)>=0)System.out.println("YES");
- for(BigInteger i = BigInteger.ONE;i.compareTo(new BigInteger("10"))<=0;i = i.add(BigInteger.ONE)) {
- System.out.println(i);
- }
- sum = sum.gcd(Add);
- boolean tr;
- tr = sum.isProbablePrime(1);
- tr = new BigInteger("7").isProbablePrime(1);
- System.out.println(tr);
- BigDecimal b = new BigDecimal("100");
- System.out.println(b.divide(new BigDecimal("3"),5,RoundingMode.CEILING));
- System.out.println("Mod Pow = " + a.modPow(b, new BigInteger("10000009"))); // returns a^b mod 10000009
- 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'
- System.out.println("GCD = " + a.gcd(b)); // finds gcd, how cool is this?
- 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.
- System.out.println("Next prime after" + a + " is " + a.nextProbablePrime());// Returns the first integer greater than a that is probably prime.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement