Problem Description
f(n)=(∏i=1nin−i+1)%1000000007You are expected to write a program to calculate f(n) when a certain n is given.
Input
Multi test cases (about 100000), every case contains an integer n in 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
2
100
Sample Output
2
148277692
官方题解:
找规律f(1)=1f(2)=1*1*2=(1)*(1*2)=1!*2!f(3)=1*1*1*2*2*3=(1)*(1*2)*(1*2*3)=1!*2!*3!式子可以简化为 f(n)=∏i=1n(n!)%MOD,直接打表不行,会超内存,可以对数据进行离线处理。排好序之后从小到大暴力。ClogC+10000000 ,C为case数目。 题目解析:以前根本不知道题目可以这么做,又学了一样新东西,离线处理。
#include#include #include #include #include