The sum of factorial
Enter N, calculate s=1! +2! +3! + ... +n! The last 6 bits (excluding the leading 0). N≤10 6, n! Said
The product of the first n positive integers.
Sample input:
10
Sample output:
Package Demo;import Java.util.scanner;public class Demo02 {public static void main (string[] args) {Scanner in=new Scanner ( system.in); int n=in.nextint (); Long sum=0;for (int i = 1; I <=n; i++) {sum=sum+jie2 (i);} String str=long.tostring (sum); Str=str.substring (Str.length () -6,str.length ()); Sum=integer.parseint (str); SYSTEM.OUT.PRINTLN (sum);} public static int jie (int num) {//if (num==1)//return 1;//else//return Jie (num-1) *num;//}public static Long Jie2 ( int num2) {long sum=1;for (int i = 1; I <=num2; i++) {sum=sum*i; String str=long.tostring (sum), if (Str.length () >6) {str=str.substring (Str.length () -7,str.length ()), sum= Integer.parseint (str); if (sum==0) {return sum=0;}}} return sum;}}
37913
Factorial sum input n, calculate s=1! +2! +3! + ... +n! The last 6 bits (excluding the leading 0). N≤10 6, n! Represents the product of the first n positive integers.