Lanqiao Cup official website fill-in-the-blank questions (sum of factorials)

Problem Description

Let S=1!+2!+3!+⋯+202320232023!, and find the last 9 digits of S.

Tip: The first part of the answer is not 0.

answer submission

This is a fill-in-the-blank question, you just need to calculate the result and submit it. The result of this question is an integer. Only fill in this integer when submitting the answer. No points will be awarded if you fill in excess content.

operating restrictions

language Maximum run time Maximum running memory
C++ 1s 256M
C 1s 256M
Java 2s 256M
Python3 3s 256M
PyPy3 3s 256M

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
      long sum=0;
        for(long i=1;i<=2023L;i++){
          sum=sum+get(i);
          
        }
        System.out.println(sum%1000000000L);
    }
    public static long get(long n){
      long s=1L;
      for(long i=1;i<=n;i++){
        s=s*i;
        if(s>1000000000L){
          s=s%1000000000L;
        }
      }
      return s%1000000000L;
    }
}

Guess you like

Origin blog.csdn.net/s44Sc21/article/details/132838474