Created
April 17, 2017 01:28
-
-
Save LuxXx/54f679879eece0881016cf307bdc37b1 to your computer and use it in GitHub Desktop.
Project Euler - Problem 20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package euler; | |
import java.math.BigInteger; | |
public class BigFact { | |
public static void main(String[] args) { | |
System.out.println(sum(f(BigInteger.valueOf(100)).toString())); | |
} | |
public static BigInteger f(BigInteger n) { | |
if (n.equals(BigInteger.ZERO)) return BigInteger.ONE; | |
else return n.multiply(f(n.subtract(BigInteger.ONE))); | |
} | |
public static int sum(String s) { | |
int sum = 0; | |
for (int i = 0; i < s.length(); i++) { | |
sum += s.charAt(i) - 48; | |
} | |
return sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment