Вы находитесь на странице: 1из 3

#include <bits/stdc++.

h>
#define DAU ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC fin.close(); fout.close(); return 0;
using namespace std;
const string problem("shop");
ifstream fin(problem + ".in");
ofstream fout(problem + ".out");
const int MOD(1e9 + 7), N(3e6 + 6), K(5e3 + 3);
inline int powlog(int a, int b) {
int p(1);
while (b) {
if (b & 1)
p = (1LL * p * a) % MOD;
a = (1LL * a * a) % MOD;
b >>= 1;
}
return p;
}
int Fact[]
{5832229,883891942,586085768,659320570,445091159,833445122,459415752,780733991,6538
39933,932575078,404741687,331275915,259444321,664010702,904637949,200712629,4929500
90,175218411,680545871,640622010,562423733,311292576,277754967,745425964,148697708,
932799119,382089807,270869842,922340607,280353761,527021329,515369747,257166585,975
463716,575048462,586537067,686481947,176260833,695786829,421168189,191511660,290460
504,244771917,872109936,262229131,646754835,64824493,224273253,161729248,303779081,
150478174,390606284,343002394,462306263,49329087,940730881,368108889,370065872,9183
80015,932520249,301590868,884439077,465992182,371334915,616752792,90722866,70603292
,638071214,362552862,390710181,865874883,514785831,589813882,673087139,426506186,35
8784546,938539998,713424640,337918762,789729940,901973881,291016723,84740400,598982
646,467047000,936670129,527676823,823189626,749395984,370246658,757001165,723784021
,986247314,855601972,610077358,846003680,417677578,821103446,598705236,308573627,54
4918953,486674670,528374878,246074934,695633220,353042626,607775756,675253462,96770
9935,628785867,648266423,575404596,119320222,20006991,301939717,455550222,77185568,
425920556,784952527,713785790,653054812,575552854,13475630,921652450,279076891,5943
3257,366804443,216026801,367885330,882011034,94434428,666921031,9387562,118187267,7
75376299,966025980,144397999,969067577,681506109,508075835,996350995,343070751,6831
40939,847313815,731664708,798587112,402168622,739181295,505678556,830996466,2789553
67,753462589,577705789,40555501,942193425,316877991,674308197,667174968,948614608,8
97080587,452630670,349606000,178244236,233739507,228107653,330112138,387643146,2772
62008,438983091,319448232,249922747,218838339,858612762,829714842,266355781,2932966
55,127549903,949419259,329305483,583467227,806500179,911262952,214615301,367482338,
173029157,373613935,909059737,52761203,964122909,944090872,718570064,776696534,8986
46949,699063532,816900862,802107029,704232160,13491337,415135107,213451656,47396629
2,629248386,884661514,344828288,181998971,962644125,311247392,155520712,531100612,2
44690698,397909416,424651150,444827492,841985643,201854004,273350277,385327964,2890
67388,303104207,219547613,321510031,876030285,3003812,196830106,89358374,214054614,
552473184,583333164,561045295,642338196,638274086,800550641,631310654,883387860,804
161300,111709550,119600261,346372397,372219298,33578230,245528064,413968735,8867126
62,720764304,563680119,197916266,942077547,832498081,640885126,981772817,316220877,
62915160,636279734,777667101,383445671,388118547,3131115,94079252,486952089,6314963
4,163734788,447628170,519946071,647807661,239874183,355680108,816428016,201908534,4
89138584,475124684,882929858,779736349,944067489,240649936,195381166,652382508,6158
88691,523274266,971141314,29900717,657415775,408460922,87239776,542578787,399638162
,434848287,402973036,414457786,794830562,257781340,820254659,823501636,493221643,52
0516137,997029065,746609325,62520076,839877705,632337006,250610591,405577532,552624
704,150165372,580861831,649341412,194816451,73344784,256361777,511204243,618764938,
853107479,510159492,955771398,306559340,575162114,911019143,476286346,951002700,512
985195,976619909,656352962,446705795,335595997,91159642,518205914,257438891,8063546
15,125975296,256853673,997029448,117825898,911249000,662460146,732669017,391328978,
441853031,499856213,136687362,452611126,302857975,620776734,90517228,58786525,81997
9953,206343064,161010321,870459212,54922618,362392872,983705908,24521750,793547831,
856674027,875510483,866315586,369840340,745364202,989315375,662159428,789163906,584
051900,545645256,314407789,467298741,536689821,680008175,982153663,707117335,318946
603,3933644,280627739,273576298,83019952,971586201,902391959,304661605,713773479,20
2016889,892007590,842723548,593388415,874067697,871628066,828416515,30227961,481731
680,718764034,121693006,521748383,913787012,26325004,587945517,13841004,870923649,5
94949908,849780883,67329730,490583920,748884386,758411347,14422365,482992017,279213
381,2962713,274262926,565617053,943182685,476625772,846049102,498918756,756732631,4
00777066,760961306,207246913,701801979,824420451,294031170,618869533,246450265,3091
07389,585588816,634407034,500985288,9800034,275182518,808427728,510234528,793541085
,537509951,443364646,898480470,961966947,646179338,919385863,691683688,809562386,52
7098245,153989605,288383190,364780842,297971990,196952301,433825518,59005736,771096
399,33973619,655065061,719417041,198609981,901686207,220087090,419159028,329493868,
433013107,7876969,128011067,916189170,164237088,647339982,988322205,754355048,28357
7946,709007156,138352104,583973322,907964432,159776284,413480157,898298593,24677026
4,138816119,171045598,750593319,905410967,245473043,295620142,301666910,510585363,5
94899090,746802624,182649597,487221569,130211316,875271397,816199673,399049059,6144
91799,160083036,660266893,152764817,542031550,935064888,372130774,199671962,8256870
4,604285098,542047622,791733054,44980955,932000693,980250487,537613530,917641340,67
5762501,219982851,140133162,67030930,801970786,987643969,977070553,196850608,365178
887,332799368,505567317,762384629,102306235,790007542,361137661,491844957,264565871
,28956144,683329545,286009160,320630673,267186061,839684660,455240596,491272195,697
367780,590836324,192832619,288834980,349923495,676467118,137475705,638913084,279623
524,601528385,579318984,275060149,787328412,757456220,795371050,145229287,542196132
,181347051,841381228,365417922,736395871,953362434,764421236,476939539,164321064,17
1300409,854528192,977996308,971034555,32497435,570474544,203293186,324804106,959646
024,312543388,173054624,7279910,294010113,250011338,422277019,479526982,803716410,8
60389494,564687177,923312466,738480252,330443760,345911460,834019527,178751788,2617
1045,797124157,565726792,961073484,753679963,638499204,987767906,119883754,63001926
6,673011305,830953181,295718955,766426499,445347299,444921340,266017073,557164995,2
47932878,161490379,713939811,267359392,916176706,152611299,366376580,376397625,1753
21373,242598826,678086196,803548836,335637468,869587169,934176551,337010212,5067824
76,799788856,901966836,446631181,527726627,910086351,178585973,49838370,405751517,3
15755202,752536427,802191747,588506565,71862705,681184885,694610617,974878978,60367
7431,461227536,180659292,963090968,636378759,216741202,188254989,493638393,74932159
8,909894132,281327429,832967428,818973522,614835904,646408235,35608217,518221879,69
3764738,311631937,281864329,277727505,87947615,140864216,944297008,16718313,3579317
35,967134156,408037215,786736151,703418312,343405294,33130644,197612258,72066478,34
0382069,500445667,947419739,368689114,79349482,448623840,816931937,889400094,493435
694,304015514,448669042,797931320,646646874,733842728,749435114,581885841,680184770
,373786007,521918307,17218650,350333519,488254082,283329610,650771553,212714400,700
691663,604392640,783983762,472462091,185681540,65825737,475513650,771913514,8689258
53,552857868,982377833,178194465,948391346,461157687,804500430,877871602,175548775,
931373054,343625310,152946940,630252132,546337320,753062203,719327341,707773520,275
061047,865618106,533950545,141816390,706820878,475706930,607184061,151623000,328091
78,600119941,738067822,654933615,666431303,642502601,858500281,756289115,828818039,
148796909,848520171,115094299,568495982,973846132,872769591,617302125,249387657,297
451219,625626035,185330920,358785493,855337765,578840098,919731442,288581846,774749
540,13186753,575738649,768929181,588415694,95936601,62016585,51174043,435949216,789
361772,943930001,565306010,157934144,504048222,921467464,315459611,143844737,894186
865,887882048,855126693,101388253,158218433,835864298,980259992,954025274,123512447
,132926535,494811697,178403293,902626430,382610562,893607353,15617214,274485242,154
436286,217816307,627132570,566813904,842725842,519138647,382974455,842956738,429093
776,12226188,990919619,353696346,311508255,873422879,925410533,104434240,232677517,
515081274,126539418,843511487,474050728};
int fact[N / 10 + 5], prodfact[K], p, pp, fcur;
inline int Ffact(int n) {
if (n < 3e6) {
p = n / 10;
fcur = fact[p];
for (int i = p * 10 + 1; i <= n; ++i)
fcur = (1LL * fcur * i) % MOD;
return fcur;
}
p = n / 12000;
pp = p - 250;
fcur = Fact[pp];
for (int i = p * 12000 + 1; i <= n; ++i)
fcur = (1LL * fcur * i) % MOD;
return fcur;
}
int t, k, n, res, aux;
int main() {
DAU
fact[0] = aux = 1;
for (int i = 1; i < N; ++i) {
aux = (1LL * aux * i) % MOD;
if (i % 10 == 0)
fact[i / 10] = aux;
}
prodfact[0] = aux = 1;
for (int i = 1; i < K; ++i) {
aux = (1LL * aux * Ffact(i)) % MOD;
prodfact[i] = powlog(aux, MOD - 2);
}
fin >> t;
while (t--) {
fin >> k;
n = k * (k + 1) / 2;
res = (1LL * Ffact(n) * prodfact[k]) % MOD;
fout << res << '\n';
}
PLEC
}

Вам также может понравиться