Formula
Time limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 996 Accepted Submission (s): 118
Problem Description
F (N)=(∏ i = 1 n i Span style= "Position:absolute; Left:0.36em; Top:-4.39em ">n ? i Span id= "mathjax-span-26" class= "Mo" style= "font-size:70.7%; Font-family:mathjax_main-web ">+ 1 )%1000000007
You were expected to write a program to calculate f (n) when a certain n was given.Input
Multi test Cases (about 100000), every case contains an integer n-a single line. Please process to the end of file. [Technical specification]
1≤n≤10000000
Output
For each n,output f (n) in a single line.
Sample Input
2100
Sample Output
2148277692 The puzzle also said that if the direct hit table will be the MLE need data of your discretization, before I know a and the size of the data itself, only the relative size of the data discretization, such as 400,880,25,69 we can be equivalent to 3 4 1 2 for their relative size relationship, But the ontology needs to use each data, cannot do so, so we can follow certain rules, such as here I each 10 data record an element, so each input I use the number that I recorded to calculate the number of rows such as we note n=10 when the factorial a[10], and F (n) that s[10], So when we calculate n=13, we can figure out 13 factorial with the 10 record a[10]*11*12*13, and F (13) is also
#include <iostream> #include <algorithm> #include <string> #include <cstdio> #include < cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include < stack> #include <map> #include <set>using namespace std; #define Lson ((root<<1) +1) #define Rson (( root<<1) +2) #define MID ((l+r) >>1) typedef long Long ll;typedef pair<int,int> P; #define for (I,t,n) for ( int i= (t);i< (n); i++) const int MAXN=1000001;CONST int Base=1000;const int inf=999999;int mod=1000000007;int a[maxn];/ /calculate factorial int s[maxn];//calculate answer int main () {int n,m,i,j,k,t; ll Ans=1,rec=1;j=0; for (i=1;i/10<maxn;i++) {rec=rec*i%mod; Ans=ans*rec%mod; if (I/10>=J)//Every 10 numbers are recorded once {a[j]=rec; S[j++]=ans; }} while (~scanf ("%d", &n) {rec=a[n/10];//finds the recorded element ANS=S[N/10]; for (i=n/10*10+1;i<=n;i++)//Use the number of records to calculate the new number {rec=rec*i%MoD Ans=ans*rec%mod; } printf ("%lld\n", ans); } return 0;}
Bestcoder Round #21 1002 Formula