阶乘之和
package 第二章;
import java.util.Scanner;
//输入n,计算S=1!+2!+3!+...+n!的末六位(不含前导0)。n<=1e6
public class 阶乘之和 {
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int sum=0;
for(int i=1;i<=n;i++)
{
int t=1;
for(int j=1;j<=i;j++)
{
t=(t*j)%1000000;
}
sum=(sum+t)%1000000;
// if(sum<=0)System.out.println(sum+" "+i);
}
System.out.println(sum);
}
}
import java.util.Scanner;
//输入n,计算S=1!+2!+3!+...+n!的末六位(不含前导0)。n<=1e6
public class 阶乘之和 {
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int sum=0;
for(int i=1;i<=n;i++)
{
int t=1;
for(int j=1;j<=i;j++)
{
t=(t*j)%1000000;
}
sum=(sum+t)%1000000;
// if(sum<=0)System.out.println(sum+" "+i);
}
System.out.println(sum);
}
}