HDU 5139 Formula 離線處理
Formula
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 361 Accepted Submission(s): 151
Problem Description
f(n)=(∏i=1nin?i+1)%1000000007
You 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
Source BestCoder Round #21
找規律
f(1)=1
f(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數目。
//702MS 4228K
#include
#include
#include
#define ll __int64
#define M 1000000007
using namespace std;
struct Keng
{
ll val;
int pos;
} p[100007],ans[100007];
int cmp(Keng a,Keng b)
{
return a.val