This solution is based on Factorial of a large number – GeeksforGeeks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
/* *Ketan Ramteke */ import java.util.*; import java.io.*; public class Solution{ static void sqr(int n,int pow) { int[] result = new int[10000]; result[0] = 1; int result_size = 1; for (int x=0; x<pow; x++){ result_size = multiply(n, result, result_size); } for (int i=result_size-1; i>=0; i--){ System.out.print(result[i]); } } static int multiply(int x, int result[], int result_size) { int carry = 0; for (int i=0; i<result_size; i++) { int prod = result[i] * x + carry; result[i] = prod % 10; carry = prod/10; } while (carry>0) { result[result_size] = carry%10; carry = carry/10; result_size++; } return result_size; } public static void main(String[] args) { sqr(739364,100); } } |
With BigInteger
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/* *Ketan Ramteke */ import java.util.*; import java.lang.*; import java.io.*; import java.math.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { BigInteger b = new BigInteger("73936466"); int power = 100; BigInteger b3 = b; for(int i = 1; i<power;i++){ b3 = b3.multiply(b); } System.out.println(b3.toString()); } } |