Java Code Examples for java.util.Scanner#nextBigInteger()
The following examples show how to use
java.util.Scanner#nextBigInteger() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkewBinary.java From interviews with MIT License | 6 votes |
public static void main(String[] args) { Scanner input = new Scanner(System.in); while (true) { BigInteger number = input.nextBigInteger(); if (number.equals(BigInteger.ZERO)) { break; } int length = (number + "").length(); BigInteger sum = BigInteger.ZERO; for (int i = 0; i < length; i++) { BigInteger mod10 = number.mod(BigInteger.TEN); BigInteger insideBrackets = BigInteger.valueOf((long) (Math .pow(2, i + 1) - 1)); sum = sum.add((mod10).multiply(insideBrackets)); number = number.divide(BigInteger.TEN); } System.out.println(sum); } }
Example 2
Source File: AddingReversedNumbers.java From interviews with MIT License | 6 votes |
public static void main(String[] args) { Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); while (numberOfTestCases != 0) { BigInteger first = input.nextBigInteger(); BigInteger second = input.nextBigInteger(); StringBuilder firstString = new StringBuilder(first + ""); StringBuilder secondString = new StringBuilder(second + ""); BigInteger firstReversed = new BigInteger(firstString.reverse() .toString()); BigInteger secondReversed = new BigInteger(secondString.reverse() .toString()); BigInteger result = firstReversed.add(secondReversed); String resultReversed = new StringBuilder(result + "").reverse() .toString(); System.out.println(resultReversed.replaceFirst("^0*", "")); numberOfTestCases--; } }
Example 3
Source File: MultipleOfSeventeen.java From interviews with MIT License | 6 votes |
public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()) { BigInteger number = input.nextBigInteger(); if (number.equals(BIGINTEGER_ZERO)) { break; } BigInteger lastDigit = number.mod(BigInteger.TEN); number = number.divide(BigInteger.TEN); BigInteger product5D = lastDigit.multiply(BIGINTEGER_FIVE); BigInteger difference = number.subtract(product5D); if (difference.mod(BIGINTEGER_SEVENTEEN).equals(BIGINTEGER_ZERO)) { System.out.println("1"); } else { System.out.println("0"); } } }
Example 4
Source File: TheHugeOne.java From interviews with MIT License | 6 votes |
public static void main(String[] args) { Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); while (numberOfTestCases != 0) { BigInteger M = input.nextBigInteger(); input.nextLine(); String[] elementsLine = input.nextLine().split(" "); boolean found = false; for (int i = 1; i < elementsLine.length; i++) { BigInteger number = new BigInteger(elementsLine[i]); if (!M.mod(number).equals(BigInteger.ZERO)) { System.out.println(M + " - Simple."); found = true; break; } } if (!found) { System.out.println(M + " - Wonderful."); } numberOfTestCases--; } }
Example 5
Source File: DataCubeColumn.java From db with GNU Affero General Public License v3.0 | 5 votes |
/** * * @param val * @return * @throws IllegalArgumentException */ public Object interpret(Object val) throws IllegalArgumentException { String s = val.toString(); Scanner sc = new Scanner(s); return sc.hasNextLong() ? sc.nextLong() : sc.hasNextInt() ? sc.nextInt() : sc.hasNextDouble() ? sc.nextDouble() : sc.hasNextBoolean() ? sc.nextBoolean() : sc.hasNextBigInteger() ? sc.nextBigInteger() : sc.hasNextFloat() ? sc.nextFloat() : sc.hasNextByte() ? sc.nextByte() : sc.hasNext() ? sc.next() : s; }
Example 6
Source File: DataCubeDimension.java From db with GNU Affero General Public License v3.0 | 5 votes |
/** * * @param val * @return * @throws IllegalArgumentException */ public Object interpret(Object val) throws IllegalArgumentException { String s = val.toString(); Scanner sc = new Scanner(s); return sc.hasNextLong() ? sc.nextLong() : sc.hasNextInt() ? sc.nextInt() : sc.hasNextDouble() ? sc.nextDouble() : sc.hasNextBoolean() ? sc.nextBoolean() : sc.hasNextBigInteger() ? sc.nextBigInteger() : sc.hasNextFloat() ? sc.nextFloat() : sc.hasNextByte() ? sc.nextByte() : sc.hasNext() ? sc.next() : s; }
Example 7
Source File: SchemaBuilder.java From db with GNU Affero General Public License v3.0 | 5 votes |
public Object interpret(Object val) throws IllegalArgumentException { String s = val.toString(); Scanner sc = new Scanner(s); return sc.hasNextInt() ? sc.nextInt() : sc.hasNextLong() ? sc.nextLong() : sc.hasNextDouble() ? sc.nextDouble() : sc.hasNextBoolean() ? sc.nextBoolean() : sc.hasNextBigInteger() ? sc.nextBigInteger() : sc.hasNextFloat() ? sc.nextFloat() : sc.hasNextByte() ? sc.nextByte() : sc.hasNext() ? sc.next() : s; }
Example 8
Source File: IntegerInquiry.java From interviews with MIT License | 5 votes |
public static void main(String[] args) { Scanner input = new Scanner(System.in); BigInteger sum = BigInteger.ZERO; while (true) { BigInteger number = input.nextBigInteger(); if (number.equals(BigInteger.ZERO)) { break; } sum = sum.add(number); } System.out.println(sum); }
Example 9
Source File: Modex.java From interviews with MIT License | 5 votes |
public static void main(String[] args) { Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); while (numberOfTestCases != 0) { BigInteger x = input.nextBigInteger(); BigInteger y = input.nextBigInteger(); BigInteger n = input.nextBigInteger(); BigInteger result = x.modPow(y, n); System.out.println(result); numberOfTestCases--; } }
Example 10
Source File: BigMod.java From interviews with MIT License | 5 votes |
public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()) { BigInteger b = input.nextBigInteger(); BigInteger p = input.nextBigInteger(); BigInteger m = input.nextBigInteger(); System.out.println(b.modPow(p, m)); } }
Example 11
Source File: WhoSaidCrisis.java From interviews with MIT License | 5 votes |
public static void main(String[] args) { Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); while (numberOfTestCases != 0) { BigInteger first = input.nextBigInteger(); BigInteger second = input.nextBigInteger(); System.out.println(first.subtract(second)); numberOfTestCases--; } }
Example 12
Source File: JavaPrimalityTest.java From Hackerrank-Solutions with MIT License | 4 votes |
public static void main(String[] args) { Scanner in = new Scanner(System.in); BigInteger n = in.nextBigInteger(); in.close(); System.out.println(n.isProbablePrime(100) ? "prime" : "not prime"); }