Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
33
Task/Left-factorials/Java/left-factorials.java
Normal file
33
Task/Left-factorials/Java/left-factorials.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import java.math.BigInteger;
|
||||
|
||||
public class LeftFac{
|
||||
public static BigInteger factorial(BigInteger n){
|
||||
BigInteger ans = BigInteger.ONE;
|
||||
for(BigInteger x = BigInteger.ONE; x.compareTo(n) <= 0; x = x.add(BigInteger.ONE)){
|
||||
ans = ans.multiply(x);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
public static BigInteger leftFact(BigInteger n){
|
||||
BigInteger ans = BigInteger.ZERO;
|
||||
for(BigInteger k = BigInteger.ZERO; k.compareTo(n.subtract(BigInteger.ONE)) <= 0; k = k.add(BigInteger.ONE)){
|
||||
ans = ans.add(factorial(k));
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
for(int i = 0; i <= 10; i++){
|
||||
System.out.println("!" + i + " = " + leftFact(BigInteger.valueOf(i)));
|
||||
}
|
||||
|
||||
for(int i = 20; i <= 110; i += 10){
|
||||
System.out.println("!" + i + " = " + leftFact(BigInteger.valueOf(i)));
|
||||
}
|
||||
|
||||
for(int i = 1000; i <= 10000; i += 1000){
|
||||
System.out.println("!" + i + " has " + leftFact(BigInteger.valueOf(i)).toString().length() + " digits");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue