Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Created January 29, 2015 14:04
Show Gist options
  • Select an option

  • Save shohan4556/6c5c12edc9e14cd5c221 to your computer and use it in GitHub Desktop.

Select an option

Save shohan4556/6c5c12edc9e14cd5c221 to your computer and use it in GitHub Desktop.
project euler 16 solution
package projecteuler; // replace
import java.math.BigInteger;
/**
*
* @author Shohan
*/
public class euler16 {
public static void main(String args[]){
long ans=0; // 64 bit data type in java
char[] ara=new char[1000]; // create an array with 1000 index
BigInteger num=new BigInteger("2"); // created BigInteger type obj named "num"
int pow=1000;
ara=num.pow(pow).toString().toCharArray(); // calculate the power of the
// "toString()" method is used to represent an object into a String
// "toCharArray()" method can be used to convert a String to an array of Character
for(int i=0;i<ara.length;i++){
ans=ans+ara[i]-'0';
// System.out.print(ara[i]+" ");
}
System.out.println(" Sum of 2^1000 is : "+ans);
int b[]=new int[10];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment