HDU 6680 Rikka with Quicksort(2019杭电多校第9场1001) 数学推导+分块

这是笔者的第一篇博客。为了能让更多的人看懂。所以本文的叙述的节奏相对很缓慢,有基础的同学可以选择性地跳读。
作为一个十八线的蒟蒻 A C M e r ACMer ,文中可能出现各种BUG和表达歧义的情况,同时,笔者对 M a r k d o w n Markdown 的编辑器使用并不是特别熟练,望各位能给我提出意见,帮助我做得更好,谢谢! (土下座)

原题题面

Rikka is interested in computer science, and she has been practicing coding for two years and a half. Today, she wants to do a simple summary of the algorithms she has learned.
One of the most important algorithms is Quicksort. Though its idea is quite simple, Rikka remembers that it took her a while to prove the time complexity. Let f(n) be the expected number of comparisons required by Quicksort on a sequence with length n. Then f ( n ) f(n) follows the following equations:
After some simple derivations, Rikka finishes the proof and obtains the result that f(n)=O(nlogn): As an outstanding undergraduate student, this problem is just a piece of cake for her.
To make the task more challenging, Rikka asks Yuta, her boyfriend, to set several exercises for her. The following is the hardest one of them:
Consider a modified version of Quicksort: the recursive process terminates once the length of the interval is less than m. At this time, the expected number of comparisons gm(n) can be described with the following equations:

Now, Yuta shows the value of n,m, and he wants Rikka to calculate g m ( n ) gm(n) . It is generally known that Rikka is not good at math. Therefore she wants you to help her calculate the answer.
Input
The first line is an integer t t ( 1 t 10 1≤t≤10 ), the number of test cases.
For each test case, the input contains a single line with two positive integers n , m n,m ( 1 m n 1 0 9 1≤m≤n≤10^9 ).
Output
For each test case, output a single line with a single number, the value of g m ( n ) gm(n) .
Clearly, gm(n) is a rational number. Therefore, you are required to print g m ( n ) gm(n) mod 1000000007 1000000007 , i.e., print x × y 1 x×y^-1 mod 1000000007 1000000007 where x / y x/y is the irreducible fraction representation of g m ( n ) gm(n) .
Sample Input
5
3 1
5 1
5 3
10 5
1000 500
Sample Output
666666674
800000013
400000008
308730177
3107840

题面分析

给你 m , n m,n ,让你求 g m ( n ) gm(n) m o d mod 1 e 9 + 7 1e9+7
首先我们观察一下这个 Σ Σ 内的两个项 g m ( j 1 ) gm(j-1) g m ( i j ) gm(i-j)
[ 1 , i ] [1,i] 内枚举 j j ,我们会发现:
j 1 = 0 , 1 , 2 , . . . , i 1 j-1=0,1,2,...,i-1
i j = i 1 , i 2 , . . . 1 , 0 i-j=i-1,i-2,...1,0
可以发现这其实是同一个东西。
所以其实原式可转化为↓↓↓

但这个式子计算起来还是很复杂,那怎么办呢?
注意到↓↓↓

我们可以很容易地 想到去消掉 Σ Σ .
于是,构造新式子

我们把不是 Σ Σ 的统统移项,得到以下两个式子:
在这里插入图片描述
再相减,整理,得到

出于个人偏好我把 i i 换成了 n n
估计大部分人都能推到这个式子,
但这个式子怎么求解呢?
或许大部分能推到这里的人都已经被劝退了…
但聪明如你,很快就能找到突破口。
如果有良好的数学基础或参加过数学竞赛,你就会发现这其实是个经典题型
我们把两边同除以 n ( n + 1 ) n(n+1) ,可以得到

我们把gm(n)/(n+1)看成an,把gm(n-1)/n看做an-1,得到

那就变成了一个累加问题,累加的起点是多少呢?
其实并不是 1 1 ,而是 m + 1 m+1
因为第 m + 1 m+1 项是第一个非0项,且容易得出这一项为 m / ( m + 2 ) m/(m+2)
所以上式变为

又一个麻烦事出现了:后面这一块儿怎么搞???
别急,先试着求下面这个

求出了 1 1 ~ n n Σ Σ ,那 ( m + 2 ) (m+2) ~ n n 其实就是 1 1 ~ n n 减去 1 1 ~ m + 1 m+1
首先,被高考数列百般折磨过的 我们很快能发现分母可以裂项

我们把这一大块 Σ Σ 列出几项,可以得到:
在这里插入图片描述
仔细观察就能发现,除了开头第一项的两个 1 / 2 1/2 以外,之后的每一项通过加减抵消,都是两个 1 / i 1/i (除了最后一项)
ok,那我们回到原来的题目,稍加整理可以得到:
在这里插入图片描述
建议各位读者务必自己推一遍来加深印象!
最后,就是对答案求逆元即可。
可能有些读者会不知道逆元是个啥,这里不再赘述,请自行查询。
简单地说呢, a / b a/b 对于 p p 的逆元=( a a m o d mod p p )*( b b 对于 p p 的逆元) m o d mod p p
看到这里,那就恭喜你AC本题啦!

呵呵,才怪。你会TLE,不停地TLE。
为什么呢?
因为这里的 Σ Σ 复杂度是 O ( n m ) O(n-m) ,而 n m n-m 又非常大(只要出题人够恶,最大 1 e 9 1 1e9-1 )。
Σ Σ 应该如何快速计算呢?
也许有人会想到用 l n ( n ) + c ln(n)+c c c 为欧拉常数)的公式去逼近答案,但是 分数的逆元需要知道其分子与分母的精确值 ,因此该方案可以就地枪毙。
这时候我们就要介绍一种巧妙的方法:分块(暴力)

分块

顾名思义,分块就是把区间分成若干块来进行处理,是个用代码长度换时间效率的操作。
比如说今天 n = 1000 n=1000 ,我们可以把 1000 1000 分成 10 10 100 100 ,把这每一个 100 100 的和事先算出结果并保存下来。
那对于一个数 m = 656 m=656 ,那前 600 600 其实是提前处理好的(利用前缀和实现),我们只要暴力去求后面的56即可。
很显然,块分的越多效率越高,但这也会导致事先存下来的结果越来越多,可能导致代码过长而无法提交
(只要代码长度和内存需求不限,我能打1e9)
这个题给出了 3000 m s 3000ms 其实时间是相当充足的 我试着选择分成了 5000 5000 个块(每个块 2 e 5 2e5 ) (虽然标程则是分成了2000块,但我为了贪HDU的榜就在代码长度的极限边缘疯狂试探,各位可以自行选择合适的区间进行分块)
首先可以用这个代码得到每个块的和:

#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long step=200000;
long long qsm(long long a,long long b,long long c)
{
    long long ans=1,base=a;
    while(b!=0)
	{
        if(b&1)
        ans=ans*base%c;
        base=base*base%c;
        b>>=1;
	}
    return ans%c;
}
int main()
{
	for(int i=1;i<=5000;i++)
	{
		//printf("%lld %lld->",(i-1)*step+1,i*step);
		long long ans=0;
		for(int j=(i-1)*step+1;j<=i*step;j++)
			ans=(ans+qsm(j,mod-2,mod)%mod)%mod;
			//这一步是统计逆元求和(采用费马小定理,不懂的请回去查查逆元)
		printf("%lld,",ans);
	}
}

运行大约 5 m i n 5min 左右会得到这一堆数据…
在这里插入图片描述
请大胆,并且勇敢地把它们复制到你的代码里…然后统计前缀和即可。
(事实上,连前缀和你都可以事先算好)

AC代码

在经历了让人骂娘的数学推导和分块技巧后,我们就可以得到最终的代码。
AC代码如下:

#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long step=200000;
//以下是大片的分块
long long a[5001]={0,118091052,131785116,352153536,850862847,428991732,414611584,583182491,896174392,124990201,323589505,206931761,988983654,858305161,425217713,413698619,414715665,478330630,532001401,40597178,482759685,232548225,560217862,630719995,160786774,867224271,754345375,576119455,843824329,49857979,817377043,877933418,47756642,342578027,586345914,446442141,749363516,771591947,343217317,32629120,398935802,68857293,968437606,441777156,93204835,182454693,196734065,701619129,768503428,470912794,72014525,573194313,738867983,285235222,132817554,304163043,35285861,250861922,516139955,379179065,183692795,389689611,543506390,769763854,31052462,373670191,840857983,367020146,54098258,781412962,174227848,104648028,599713848,993149165,704685486,307090292,469396434,67700252,659789365,448472765,456643961,47455224,273593776,96158151,866612273,751077136,990010787,151551952,86872827,817727400,102820197,655694974,28185869,893496173,427196953,543956351,369115458,511875420,703187315,367623814,189435206,822865222,367568985,982567104,204894272,989468986,813291513,532238400,850856025,353723944,646422091,169078682,389332165,199016196,257134087,89401236,969152043,255020093,898253226,274836613,699071793,827249742,247052267,587240731,281418569,980927262,197837567,667869657,639806788,134558025,134239210,337418715,403345377,578501799,100623182,196155066,603661715,462457033,503291518,620969426,328569085,633470314,283177385,721937275,689807350,149992644,204440151,559376136,775588884,934012348,795790096,781025085,677557667,372473316,887235233,102452577,828513970,105905930,689010280,425213825,558196091,224390157,283927529,717859527,955209097,950804136,363393780,722182354,899772563,814056465,351264506,715604119,969997742,9908974,65756994,357593050,28699444,37465593,650590847,853427962,23083244,569668678,378502735,778943897,890627771,411546796,513858302,982781493,671691476,62358974,934744009,327886125,890702901,256960121,712408225,783211611,204794185,521545503,419628499,792012729,985968231,226260985,397316849,867169170,661425854,333043889,120332596,880797499,652197633,290649867,544490628,118674346,58796548,858227890,211054111,385174173,612397191,209647448,659802176,914281364,936024665,916859008,731598650,690190169,471209919,666401078,884842952,76906371,693773595,185282570,915161368,774980465,422045434,479175425,948262056,222136099,114510549,935939795,987114971,221123203,885344792,258892876,51816306,353968481,444212249,118902244,216265929,936656056,422103538,282977247,665915027,625327049,676838306,595001633,582079856,693728179,126805007,200740079,579241904,259940450,764551612,374681877,649459652,29860243,956298180,966501167,332299133,377496463,138535479,973454198,338402575,549998562,463566624,683393756,435363108,701178337,742601738,386600011,782103008,899704980,43249130,933551108,749087341,518744012,820468954,641650320,803852494,858515125,64250767,339758727,760370368,395998646,82392807,371144566,840917056,648203573,217850784,270518674,158333836,456541281,615568434,303962314,653688076,496830008,114340000,726317863,792034163,279780217,78145485,775906948,898963757,298704831,298475456,89552584,9361075,498217473,271157956,355284752,932511891,346897655,275181087,871319715,805220866,603948208,212907660,388158757,606719565,992301868,282623520,272206076,32176290,337928137,328345548,385601531,21411627,740739850,89949909,874279910,214334658,721313407,842842872,700176444,924833221,380473937,240954799,489897412,856144573,999612030,643033151,464528272,522017862,51650593,367794839,218450551,129579181,581022501,447000608,750678394,112690503,721378979,6314451,154276233,302351311,366114374,638441816,349532389,337582189,446647611,970404432,49341525,272027785,880897112,854027573,631695800,902620258,285475053,429010688,688158583,264794462,486740329,120580617,698145367,770823936,739567288,277610613,461491198,243849878,24815707,237676884,286878021,63956382,757812480,365765156,610087711,549949010,909715282,82065213,71347275,711316316,704974366,486901062,588226877,603586096,446113263,592704334,561721545,661325950,933849411,45970546,2793756,823457921,721192327,581960715,533832813,43086126,63965068,639134744,922642952,834344221,236953710,876590700,112183037,479560418,743692132,613072198,767683245,274711143,562899998,893286299,700370167,581105403,605115604,489965267,667395305,662684595,774797253,272462255,698822391,859154730,314742526,173026752,607672027,958722126,724148786,364353395,394325096,23864281,819579337,159354481,831637081,514207796,541262854,419114703,547679135,519893462,805392010,330107744,466997310,985041438,840690617,978826950,919433703,346535455,69898686,582329781,23312128,255257792,255256645,847446258,224727034,685187932,391435997,719458091,245853096,940736872,131739081,632804317,447566131,905871735,860826585,449481106,485223822,97625822,212336462,773552418,676493393,221000168,926282633,242255317,534007544,62453652,349622713,150952250,411236816,588351154,456599721,464623868,363806407,242071425,456164018,965145919,488491869,701723857,319107790,859801440,212916315,834200028,857011788,747284854,906298641,155949518,327169072,270674434,246320247,93897476,859356498,736180045,797698342,506189687,329576732,902083758,641254513,718874494,416942149,90690000,149735558,653768636,447131661,304909270,844324629,229878499,580192007,556462483,842221474,696267399,471150759,905192418,815608823,583039708,104214966,961196396,199885473,780692872,644068387,708453389,302550631,85134894,964479387,932837050,677216477,843164804,826479794,427993337,553591752,832245643,316930018,856840288,104838793,38219427,789683792,503401812,512284521,693186626,475402270,467532590,698926392,662910040,546850878,997312887,61987858,221946926,503827344,954915793,814003210,903188052,746533996,511780136,760199413,583739716,988723516,241553084,596477581,710834775,451553785,127645408,43485249,4883636,791641106,80432544,596575978,380184517,678981252,645009522,904419449,689270206,14960843,998366317,338687086,301121717,705760886,308822731,278594054,968250713,516088155,171242732,35640831,119566712,737255419,465505765,396911912,420422329,484978194,757545317,467100525,77725251,182042953,863116138,993889378,376888635,602825537,887679473,707022133,727036820,357610371,476572576,324306079,465533620,205682137,376913860,274405768,10797375,832175473,412729758,956210918,132874840,71876636,343357958,472402625,734715148,590092279,721120300,754001642,693991272,656509042,235697353,326309740,487176776,336796521,543281447,811245553,571779859,217908143,917765313,185769589,950698692,147871121,102009592,736992019,819805595,524762134,688455779,774587361,192324977,442776483,600721810,631415949,491781896,396971565,116865018,622481380,521571064,338917849,858845216,359781984,723387874,354787880,72124106,309050260,900687162,325404383,722122269,663435166,850069826,961527522,754365674,163429900,176123993,124517558,923891432,555399250,583431218,868377427,162786880,918452613,523993634,504800835,365577827,262256163,271577191,93380285,333796645,972185917,122339082,519792966,281560558,673855252,270485857,924204554,757391291,92350064,249028438,145183138,249512846,517530377,30931113,776859797,804697242,82982052,807766089,523354673,363147261,607663452,948069799,231563732,371305670,378969324,2678042,606296380,539619295,209824447,361350762,708682064,32359062,148639235,288068773,858283178,912798566,365234606,761982339,852140869,209193991,868393827,435715419,497325902,850740658,140160826,899257072,829289094,392913674,797375680,712887898,731812076,610724075,708624844,786084989,37310523,6230138,662784752,689864585,832033471,251425940,909854277,182499570,494105207,340761411,218041512,488893754,912380601,135261458,657819343,187545790,668026423,805013063,3422905,741181427,892360657,596992336,837974608,206301425,882497501,692051824,638023512,213127954,104983300,178562885,390132131,312626756,204357829,958981569,579745119,1363462,92943664,701755750,723458096,460824172,960681658,115673709,672465850,662086934,980126532,892699972,878924192,468101026,496054345,216000757,280690766,596999887,329993196,539141160,63519057,78942524,467938216,269237815,75859333,461783075,487119001,684795599,368319939,512264137,675364544,464749919,533532501,709999239,742615198,978698916,412766728,57561996,708785768,564459386,384462096,182991830,182828104,104703842,473397012,689507243,527431010,615303551,478341,997745224,824242484,383843615,771521821,162884470,867002284,133238984,172984625,313555047,601357645,36606434,6790813,585506829,438923680,509823702,265194867,864932729,680989766,753370300,886217291,779100888,887556115,74015895,54016589,157785666,352306695,777159289,222329738,423878481,457511320,952435400,858636442,569955238,885037288,514054269,640959374,723031173,814623626,463501184,979589251,468584771,580950429,330378619,611308373,351463145,329390279,963135760,223433081,919575287,749988583,833252344,788666556,627201769,934053907,330294645,613716167,799798290,26036726,673651798,949035156,240396921,785338694,683939200,553685007,247128288,867568692,575099691,898230214,904689542,490416294,868034969,961514453,931574203,260746868,147760321,510146255,51276985,403731998,496569900,250498386,963861282,505482329,864750437,80796413,933453471,170354105,373684905,767998881,852394289,93299676,63017933,743183614,945055596,33806563,889242755,965094181,556338152,810300697,968247577,604099762,606067878,686522632,261693514,227873856,334246575,83124649,915350215,12612927,965381167,567996038,282745622,356465609,299997342,510827877,393312363,905110688,308555392,707420981,3186971,169752367,720363680,971258492,327814593,130185675,620766954,21176933,737286144,533465901,996285937,580679882,413453713,65035579,803418750,236035538,106126136,576273612,601190689,525495121,278583890,992040934,723010068,698186115,157076220,739279481,98117524,322175442,220842191,753141322,880789034,991710582,766477194,411637971,559701633,694992486,389320322,792251911,689738340,682679735,905656986,595369511,177951697,588483682,787790394,121377354,83375879,226138702,767163601,794430344,331825105,134745860,253840910,102514120,324574626,526706918,54000561,952719094,573792509,561704679,815751985,252123848,55159067,212556253,36477176,743492569,217519289,508870843,23265141,908260885,620026927,714448331,601363143,452726676,562314455,42811837,360400817,57000872,890542788,782885567,519075965,708755600,99658760,704636677,184378707,741249193,428605821,214759183,36775800,488576546,212663667,917764163,30657254,171493517,23956881,88340884,235906945,904798042,866776371,468545088,491894718,214874981,938656198,969875420,444100118,860793243,241188149,231495454,991013050,901742091,169690914,425053378,584781873,347841262,89982676,419804546,478108192,35201885,922833972,311503683,87836638,212543149,928016907,809505467,517543268,544568455,556299757,531585893,281330460,73173298,760894256,488114569,846701075,241561692,650744960,518238192,233072038,493244822,439882215,932873862,624649941,259928420,31609297,158112252,622877529,888063882,47719431,142890572,143341507,795907323,614706482,226495954,549820718,452449432,170300965,187832741,201359575,30155790,729476157,309051277,370325384,406168110,559483249,28560627,535606376,629393307,687583585,153524423,96026526,434303759,977206244,617150043,31571356,523747011,803792711,562226787,718173047,602881980,92327603,184488646,687173971,545470701,779342807,282968777,484767276,518133389,199604394,255611765,212765771,183269156,920185774,348162696,85960908,55091895,564760990,5812313,299540974,389601639,64057823,121220326,840760578,388405988,647126047,730274845,541302713,935792998,502472590,433114696,789732535,918225765,853573275,495671263,640797824,605001379,925979026,695572788,745344881,765428960,393325475,673900697,937056027,495777107,298512807,372935859,42442116,136148221,205766653,735716157,822693451,719198222,795763216,874409958,160504840,4626673,597314971,139862452,544631828,224526804,353004238,818768378,159689915,777506008,413608331,605265895,253135777,452311169,988030273,669055870,933712532,180491922,921819325,482518109,266523512,823101673,261069764,306014386,183255993,70816425,274929028,96452664,748780184,244145424,733796988,357342231,905137027,169779748,684831532,954635814,858861878,857504673,442449324,114168020,409685572,716743222,72881715,750221072,501111164,622506329,993293132,573326396,628048448,500750830,876870172,670775527,624356004,474132222,170050548,274478830,569359824,384015457,22727053,288998616,639250690,685471036,88302824,710731780,749503487,373108872,353663226,977877977,303375406,805166046,799264621,586709366,807397783,776618153,871106853,899087217,287807012,843095401,6376241,415079208,518311343,90922623,175034242,954030529,38012644,261646670,709582648,216478728,4931670,954179917,93529755,738172996,481354582,230856754,117521496,191888745,70068639,606195754,274784108,884009715,234565007,180238091,552357377,373123020,163033578,361410317,838302892,249434034,639926171,339751393,584444087,777237974,620802905,492217953,506006927,910264493,918459831,464695526,715990270,68555353,586566033,165515730,523879859,654856541,711750068,426292023,155543170,586085846,798720248,833468156,761678624,459514395,701133103,659510030,353654252,358262187,146991577,399405802,845807265,471225146,520567588,218379349,309901918,646064631,570023153,333120244,316245098,82583456,446334014,650952227,693807322,108554268,424180818,878717812,192579541,504445675,976072448,31344958,257885108,273239085,808922981,10466110,330410976,672533476,232154960,156270468,568861606,934388929,245974640,827773808,479272801,29429654,12597897,956489847,570826143,805629695,773669252,778750378,169936378,84696758,418285180,718554635,148796042,513849192,98461105,975571850,432380536,443675769,995135198,697936121,139596323,709816171,283619213,591634386,114194905,374227051,7575594,585586671,316860805,536754596,384067962,592224148,916875144,911869260,339547018,30260639,684218543,628548987,506832875,279197812,733356292,636057943,649677288,258409088,536702659,879521165,659626533,493867093,427593207,581286004,451673303,804582166,809629311,261355942,841989254,179444635,225749064,349105965,844440731,883169482,552548391,497947332,876010675,676432885,933870794,453476800,146706606,696627767,135527844,420362191,213592530,679747781,33614108,644500630,491230771,692649936,733072192,348046442,509786365,418092342,431192599,570285530,175274079,861913018,836086472,66319355,6842073,877737507,987361223,975939793,742552016,934992796,178532562,971255062,244122678,82947194,219064737,746836747,925033035,692263212,369868640,458799026,38674465,196876070,13139551,464197615,475791428,426424255,123597404,716091400,695628180,59623124,418378380,930718472,870212512,586272496,348812120,989714289,604619827,53666651,790183504,773633851,658088188,405940115,308638511,759060300,72895198,850414106,898114767,208160838,602941073,986595910,366866938,610751710,368472300,456594699,305034055,892154547,85249481,868961857,324395860,303320798,720815706,761977544,20179650,696565280,198957631,998312224,528527210,54495652,485045701,807265052,355990054,21515267,259748739,754713825,186188553,825949322,802636725,809269996,266006051,205182163,955105369,410813091,103394412,424668430,648225444,786260045,396911112,858530186,893489034,961345791,880551578,863386143,719816862,777716007,19834344,463720802,572148354,248227683,348265435,206511540,827100585,481554976,852870753,230564710,457844446,703928773,234137193,597954220,118745997,269116422,751840633,582096888,23275678,757368350,366220326,710365686,420271415,911094259,180656522,384546473,479347367,609760940,880104714,714048470,583133158,23852513,729640049,15417102,404536529,753735921,381591226,115515499,133759128,2736991,33249988,171120137,147401666,160269947,222338320,44897177,623182537,700404130,361400329,475138745,653896386,619980442,285230899,200955978,255955190,745084151,855017331,489521049,186810617,787445526,623506021,111203430,828455744,581132038,200611780,805802639,135966090,245055073,444289096,250157952,179196881,953849339,105489146,804782546,52529802,747813141,458380640,242297742,548479388,255142973,175889197,132991558,711891189,829480652,795561236,121530434,343999339,16774400,662821002,951487784,559179283,106332457,719427248,729275519,697667717,738716140,177933619,873467472,91701270,803289137,318745908,259996783,848126445,383109865,457138034,156303215,959947789,552475716,480627467,817650405,302247251,387728564,471275552,727270055,400275713,528768656,976768317,178415400,941933650,514571975,7787184,24030928,215889195,831599699,296265427,364763894,203493237,485568509,180565088,512366922,457710076,415439922,999012392,694776087,385097202,37832980,734105069,212987354,502619003,148286386,482872037,348408267,797295058,732267363,493214602,714935705,338276566,379548647,939426768,877026369,999620535,803752900,525359782,123698724,33818475,138368113,92065360,847793947,100139019,270960514,49227845,168778068,343748024,200990276,927767147,125532852,614782912,744313034,16943977,730909397,947204480,510079997,139593577,110727585,492578498,131343421,676013633,538966970,467287137,668247071,419643480,578649717,904839806,216889481,123897591,292780837,977368947,61802260,427368788,3054292,774190687,778563714,374731360,203923079,877272720,659557971,531108761,859608878,905150906,598368772,305057029,541929729,594769885,166370919,210726220,53662445,375036460,772443873,697614778,548523662,555365239,880018596,900627600,945863220,865063155,701547689,614948151,38797506,584498265,349961579,271377731,415780365,609839256,985745515,781998129,579146471,433247017,774329259,475699592,896718886,974263784,591693856,18892649,576199515,856469562,856898562,914707796,568529081,716462051,369415512,528128542,544369851,6367068,663901428,300541152,13468965,961379107,568023074,280126187,630795503,254932199,920144257,578592935,874184085,343371792,99597865,479549259,125035720,805394636,105388524,117607484,303598978,304984457,132326267,595704087,104887806,152511062,781312990,844889800,361707440,896997319,120003696,597324237,638887959,149038051,622752514,173051431,436724618,3110269,695111884,37306364,381020912,179798427,849190016,246387178,490136846,100794311,526664174,529379269,721131520,846570792,220756385,433843174,452738272,604552578,349104152,16375709,954774346,441482173,580997265,878401796,528744458,412202376,101668945,657697289,721662050,322219183,479058680,34903606,649500986,158969555,868044928,126567797,347145570,772182203,136761538,767528501,767878569,472659253,593064203,235018613,89995812,332260211,140389733,723423493,589475774,193337730,525162621,834970609,412988112,194616113,355846079,972469894,594024286,110741000,159636830,556418794,200327303,537127749,375416340,916391869,929375358,530395304,807610157,329381410,946655,347145179,701510380,950800674,50592300,907873833,225767276,794552800,896753015,35678980,967815947,813874900,721844178,256719202,223115714,677369286,156470595,278204609,985254863,306038659,78127567,89593584,40582483,77935437,777955000,269111472,297508524,348728752,253861096,81046223,251396326,620054019,84867167,862982397,62441141,984287705,157716767,309717846,605117329,603602073,184797691,451936456,188214443,195306674,103134043,215012761,518563378,904446807,205168404,520845012,954149397,30322583,550930292,163509977,530946037,8086306,674433620,747480987,415238738,189466427,728589875,721094704,609464628,180712171,518427614,442530234,129506178,49580808,285898954,313927007,964794974,254243053,378682964,766814528,610808377,553302322,291632057,438070596,103828666,984201335,200466607,775633831,784415285,514302006,317977337,373456108,787723918,235532409,683748646,590232700,952667671,330157714,667970695,67263150,386951365,971372656,388465258,236306822,537178798,318510613,994671551,260092447,287241626,560590812,343833099,613682365,788219381,236755732,877289399,132089069,460244663,672041869,309204578,231336174,485559325,966969831,791417374,164647776,999929453,692978819,414488509,69208632,990402810,259001289,739742244,841715080,520179556,881301537,295413469,938650824,403991302,408416115,339429897,55307197,935403111,132803507,946025195,42231905,545100479,106080422,2692128,824532729,518451019,518853984,214522456,375292021,135467258,848360182,756012374,699884055,597877284,217034841,17066653,564372254,887050543,837606902,416763362,560650510,77258855,781257770,943795392,330935039,81295069,138889657,740559533,264241622,238921781,810053156,596673268,893521510,182073881,318609290,896518203,41680029,638951277,668513191,885397350,61551384,114986697,446219185,180465751,836618901,75597878,775228687,495534314,273593174,338374498,866727248,925766549,172339539,440882837,376369870,96951902,325693986,854279227,156451501,908287670,410111929,479924583,791506629,387492637,553796648,552273609,980478670,865138120,479703339,354433607,644483351,503207744,710202120,697714680,918636150,596118465,568422511,321395453,677567971,179517976,557813815,594687718,192108024,414503775,478981488,858902099,951552765,640928350,739523040,331402646,764302911,987088281,391074912,149972701,709416215,340107172,241300320,867450371,917224129,390530208,294171284,490519293,418455767,645390245,470308668,483725005,266984991,470676982,63942492,1134047,547618800,501726023,658329425,684829279,989741295,426248682,463149641,125201755,204338784,230946821,706741700,25411594,708060227,120274590,253414021,876908553,769567514,502661825,964207431,835903927,653254470,987952916,71256835,583769015,94360576,906043021,525246122,124989365,757141962,620821249,122861365,338380386,692061707,991002586,521611602,923515214,50243567,168406388,689017912,229302101,59261810,230412129,723045376,140369799,59279012,765618698,744988911,633578712,985338057,179471594,57488612,697751912,849354694,566463795,691857063,848352905,850384615,572248750,77436071,399060279,115037504,711954020,367164077,544933179,447556740,508048619,876118299,448207890,672530066,967872762,887313696,429567010,943143990,418894535,689722994,252823026,919927739,7640983,139840714,657993805,557622068,642148916,307226371,964432490,341502520,335231157,657840490,479392211,865157446,232981111,230280797,501489102,141177778,114475561,492330355,77877374,817786184,305680654,680450359,197228297,717192052,938678095,787714553,952009027,669049481,816088934,9111083,709662567,851363408,579923661,325958923,719233062,231897653,3993008,35605828,703074914,126084531,707016220,509230729,605652324,889708252,515129487,531417703,346883619,620727511,998978830,238926721,92258301,181532523,6939483,168081727,342587538,108924606,159809988,624927861,457826839,802711910,119537379,818294955,658710961,360510720,966728607,752236250,705779285,437326385,614264760,506235217,197871609,746964285,738799888,156214377,584044014,987850071,210262735,610645907,39097637,388372296,783176336,458269683,375612819,875872494,954691156,598566962,805615386,775866018,268302882,820597216,201432306,100319367,24924820,31911526,976051473,334433106,887995479,712166600,347079899,462308973,659186764,92725569,252685953,608469139,920583806,629616355,466196732,251058077,729740873,641252125,244057595,58801831,609552776,391560469,61943138,164276036,149822070,521552571,852454562,252613438,578977868,813714149,546971163,330431605,74694115,25246561,333357499,460935982,603816221,511148729,65482443,383150234,245024013,474719057,277516903,523974651,928313101,823461185,162184988,2172255,752525383,31243562,306941478,950445310,944105072,5172598,21379865,398135271,864181207,114151833,535598917,247041018,552983980,461686231,600154939,544877511,800525833,167884980,385952992,411649632,211694475,145590959,996823354,366823086,301731217,583263772,158437645,121601960,322556032,344567051,295939356,241284092,178810392,814122049,139184573,411433340,388679881,873746391,172505690,357750074,435966039,634239964,489700312,213956259,218451156,202037083,609102439,736562005,167439113,365509820,68882186,620742980,106595323,14100836,878228936,996723914,303055867,467000470,683257682,299338056,783993266,939934944,224208556,728418321,327670219,67234202,930950949,383151402,171705417,134812902,576039658,632315509,418595562,171288493,198661324,644263724,250135616,546759992,40684956,543727024,795465485,187192861,353449608,49624230,960060448,184638362,176294597,814567967,712368242,505198517,179505286,938607255,736940869,437674592,737574224,19962578,947124421,654613140,21263523,994795808,553096208,102272809,320623362,162683597,467303770,679198670,21806222,856666993,75666207,294848861,560824245,990643132,319452504,907577821,437213341,37463624,225428987,855118884,677755480,714938682,57751099,654782616,495231805,240764567,265853546,447151679,52881325,91458950,170139900,19295699,879962469,77205191,311533460,544542348,122486129,565559577,694813420,89538434,303882976,181932061,817349290,486473148,328766954,305892652,248912244,674271603,71158154,825988480,602837621,709270808,559785554,9223790,99574204,51004918,999252378,517693451,267502299,54797620,464530914,89032042,504632416,145471870,711729163,406310330,111049731,367560961,582314470,444389855,419795747,244914769,48360310,623423341,886831643,525235567,541455459,938476653,684827834,803651473,116541713,873740110,674894847,862637937,388512158,148915300,84827183,254348147,285124736,403805515,869964719,862474106,414731473,998641122,705878512,978980906,704969665,824786002,401578640,564520516,152514701,438029626,171097497,222628872,466140818,299220351,652453657,679628159,154746588,267944795,299627480,949190479,206082391,255518084,774437358,701773251,667672577,866052214,472858050,904754828,351929143,41639921,176023874,664772055,162950692,29347063,596118344,489301121,620905625,177459985,790611176,102917944,504120835,706211540,25994858,930312340,170067577,612518969,986467773,532184188,970674938,800313988,410476577,220416504,272142993,772765759,157697320,641426829,348924817,310105167,947675700,506741717,124364347,280339783,787205311,114272799,526520009,400330063,218295125,997650592,230627809,513814933,84281546,49008407,161099736,987612729,420679068,198304456,809940066,933859524,72446958,848966782,293147520,819239024,392427618,189057315,549916690,587645819,218788270,972474975,997827679,996668022,674639690,710664871,404570801,698207091,514107803,990014696,586134526,286741725,78806692,525104327,744328492,537488353,707429828,233904191,761725773,539568144,824817291,741799043,508182836,9781308,375639382,957514445,232743404,962820002,127624510,478659602,340601523,693105268,919025158,285402329,896388244,701508644,547181000,661078644,345808929,870752337,881378127,995576586,117944998,201317582,937942017,85397505,412647479,643201138,550793122,787597283,168022604,916548913,862960239,444754704,406336554,486756235,511600925,416450488,655251049,6588984,882751712,257684493,949496252,450896278,57705021,314369310,948201463,862759429,832367982,961090565,274883629,792473686,57877200,739184470,20995726,846160714,709785953,648682107,357907860,706764295,989096096,26940903,42414093,954748079,253457985,579800892,410848486,315054893,185142833,581475372,412439456,642403342,554090479,996864439,380146893,314789088,330491898,87398348,297291573,948518966,545010200,325701048,606803136,754866270,525567444,728510619,154283255,510732196,48837951,342557671,768781733,390763812,444874541,243371404,437195251,747739429,883054653,21000986,212316283,62204993,861056733,453997972,419329683,769170283,926978719,285688757,917971871,33786869,571624106,354911385,60697325,517713469,985270050,296504173,940615716,141330207,958346240,54336093,234653102,548946015,925783297,728076893,375192508,324550530,439511417,896636074,162832994,29592802,773022377,472354111,148401912,29835607,754187445,494051616,314757370,345563692,356875758,328789811,438076067,77418694,377256767,761833941,598486502,399103531,313975947,128715670,284115672,46225684,728172165,838902076,884634699,516583631,759171441,655796099,687774266,470905314,812115154,149423316,680451919,869196902,839752306,246917618,494400859,784888627,38688633,345416263,962131613,994443296,736426648,458787095,979060835,275257809,92888986,426504471,994718648,856661137,767065193,656853465,739347297,416833847,692441488,535280760,913873368,421643184,37700621,428338778,348752839,745379770,469533358,763446553,304545361,214536406,54063977,923214824,776500368,248507072,621500111,271468625,169993537,308405010,978917469,659012647,802046423,455085689,207579601,807967750,464151058,890686429,226174543,906777804,719800452,91970490,338891615,525296433,745428382,108077806,35145836,243961834,887082601,432858362,433482642,160887535,568811663,641626644,571910045,96704271,223894066,93410447,215839651,149835950,303531220,649542369,982413868,593821548,110252715,922667844,357518292,732134937,392357712,461808805,89556912,400470562,557935908,388359103,177336459,937234627,631186410,966862650,578935148,10670968,133468398,241541708,624599725,86981383,358226317,839057049,44437848,423324011,404550936,940520422,935954880,36587062,630553235,424386319,604460250,502451213,738438158,577633802,635945742,514856027,149525854,370156870,190595578,601645636,657198834,680274764,284588951,414621548,324489921,399476151,585726259,258852770,377993058,7711887,628149901,902684712,851336326,381158478,574990427,97512179,655030564,365247585,330451044,705855646,506524916,315905545,726951312,490232347,686925424,393619916,735143858,821825759,434540922,635368932,739169033,856062064,526554877,2481686,788155122,425245249,888704487,789463306,878208340,663808946,889988928,599620089,901725912,43406748,242229008,328435336,486112275,846653285,156127534,229674067,924292815,320110712,766763610,340754748,217910896,910220076,407251734,825770593,338382004,988682509,968738936,751253502,331145915,839522170,613544544,987224005,941293764,367516811,115916469,487909246,779368947,845985642,297508556,583254331,5900913,255876193,939061621,783965424,154940923,985283225,730230681,137249651,99899193,812525234,645050168,97003320,407362567,677310529,846435386,192093724,565893846,974349344,548085818,908460806,249254845,43002631,492381185,510359419,324937707,878743595,758053040,597024903,651182694,30822074,894700066,554675526,449081524,448658469,895635947,724347610,528856605,684735882,989189220,245105506,713864172,46176933,501794343,689380474,333594158,194791635,216290773,501961484,197268055,816760265,298541615,386407951,733014824,369456330,340712179,270394253,508654771,809506149,81963115,518783105,254735748,150080326,392383837,767993416,190266793,554496536,651836524,793736618,218010554,97952342,780290996,550635677,754464552,748857824,58692016,107483141,565700674,306736827,644366287,341090083,774850928,204351368,338777939,512624104,729934605,467755896,377011917,206024532,907170550,523931614,693719398,560860718,750585392,672301076,355318126,915430586,964154780,708806905,221350327,467567546,600264740,502297121,529170626,706512887,330637130,758234881,210775620,421457879,88697293,478950911,638595247,775584853,735458186,308680242,814617195,488443254,397401038,680786107,428611519,503883726,571399330,186680789,948374321,134364958,232233139,696714685,332811887,168036145,327475905,226913942,309138459,569710941,630832581,20211568,974245672,684359249,41459539,901649114,549615120,600316496,346790936,291517427,730575463,848606017,408490792,121704889,120353494,258395640,383061722,114844245,136260081,367584193,481687180,246662420,332622025,588183710,762352852,624580021,550445895,225671685,156929893,512174691,8924319,761054054,288228828,111866048,254151233,517308236,354626779,330494642,588650841,936962417,36568745,187244604,946375384,819961916,776352455,173782192,229427307,690303499,698810256,413970540,48584830,756485879,974404063,362577994,598091382,178570610,588532024,628561345,717529240,12641465,828248860,75056913,267991832,622113983,808619509,838571190,906168896,82275516,422304215,927495181,984899660,235306228,343496857,944759978,531973767,154470819,195827326,649531385,526946964,295913239,833419153,494867530,310480475,897098482,383326607,969146312,389523430,151825562,591535768,576456870,225263170,534536013,739654588,247401538,963727571,127822902,50337310,161315870,23946937,870424072,922007339,375309158,718210873,547004030,952134134,238175627,833230953,445875955,507789981,912247823,489706518,382723130,672519374,658068212,53022494,661455418,692189497,697254883,455895183,506737160,807808461,224538862,276447711,100393169,591973225,563872195,776914011,337957337,802230804,846488572,459088002,810295441,332130132,982728639,253580317,155939192,931987285,649562009,512418580,347671371,165314384,486959004,879087386,82065947,561382865,663640720,158038789,209657423,203997555,66065240,599550080,533918357,852504791,280593657,42809780,572187385,855329880,534626056,416908826,193787476,690415465,898189614,964383243,599511822,907340663,201266131,124886908,344265742,951507606,267845701,335206195,753195616,160344823,206583001,79095442,771400048,835196147,846618319,684726849,31049094,114277013,999227234,852559093,230066095,578309352,287719367,376487,1313463,683216732,810874363,513268871,516287974,496573943,264379534,525001059,44608576,510012698,309603407,188957233,371897796,354555056,99375046,749604468,216855980,947820846,437240670,279551642,701897265,721127782,73438136,724748524,265083587,54044476,614188723,499763899,684136752,669124579,708790143,474486956,200966402,462594699,617850059,282450759,39977297,950049203,137491188,602845761,359787010,510064414,993720571,132388329,595796685,251718271,917733803,348329439,69583559,257683538,43399581,940967829,584673039,569260185,966485706,637066463,245987341,723286813,495890585,542341523,687057754,60220304,832728791,800936139,899723896,185184676,420486171,487894734,804849281,242102692,432336210,414082655,156904291,967822590,608317873,699593349,116298175,602999645,548718649,381523763,603145631,848612129,515502225,57935986,696592912,373909325,975387897,864637045,387177794,71824160,403179547,142526612,948149245,219008766,474450412,669072720,728988203,334283865,672436906,516789695,97235827,191755460,678646592,458880883,917426610,808549732,715345919,831031375,467178543,289789063,181966759,918294066,64456377,3559060,408738944,453085118,922652937,126134268,414147720,888365339,962297749,901737713,977953688,641786165,796346420,257055103,149130799,583733015,121564684,471358233,865066177,490936132,256219657,49481360,216112267,750281543,391461636,485814930,784874284,601710292,652600279,372302007,982946935,31822508,505254694,793858010,289888453,952791678,122296366,204010413,134601929,163237056,489653874,892939343,800184178,366612092,858072770,258903058,1678701,215164400,690997525,863550644,120327904,96581786,86598346,55391408,622656401,339582033,902555006,953235227,194412403,558933200,615425693,888344297,887939923,837649285,949923647,615799645,70310367,138132333,624498158,57376948,635764429,146798579,935616311,57331310,563983816,744770176,200696550,539338349,898062578,712677218,188885984,227786507,862811217,47651384,337092868,711925195,465450068,202402991,59537017,302995554,373714865,22807970,324825441,832648407,968387216,457791754,160622415,555844573,926290942,562381190,871938403,517537305,987355173,740101661,372006781,787370663,642489444,615512494,736491676,732370100,23856382,711741079,112057639,213602999,716113327,711611140,937345277,755811662,566795679,281610065,684541535,603204643,285658744,811896318,810935537,93276130,492787178,428774132,335481958,164502056,463151787,420341971,208414503,597413606,656834874,302632693,715109265,820534308,623746301,996519610,25708961,17521144,904668912,245373028,334144758,802890260,921139816,506858551,133584382,244296386,859600795,816764217,469419028,361475155,192356373,601531510,660197798,270511025,822470536,277525958,988694221,131547063,997475198,743559453,235509700,782203138,123152263,680488382,864665482,240658065,339438221,572329888,439783648,20492736,208742961,721218776,659776813,570650625,47364802,278469769,546356498,722497481,845121758,259517018,738217519,547506754,720167105,630661674,815462449,448155922,884793357,781206546,995125249,323625646,918692934,834899819,499869217,600726894,678032810,626954857,373438967,828605019,916504302,263946753,148572685,971853825,218583946,103908078,453187978,703969958,168885092,54901976,998334511,999877664,686460769,409706828,924640668,185757780,366726304,197869198,598665078,761540842,176342356,666488597,36808930,788424797,87337837,931602582,727457261,380244524,54466161,308011481,213028136,522005648,492993046,195890504,868429048,237361021,640243321,378815014,422553392,859410361,403814690,752423676,15953358,797689258,324901805,737008379,159029843,356175940,121100983,447720326,501612385,218745010,656718625,581873978,242824585,524689675,930115770,564910980,160218261,860076001,273049618,309375619,643356049,320013223,398839227,100091731,913171141,507348215,928128317,831075362,813320294,535245114,795151,542916073,593823849,417113438,770689743,758924944,674444263,482474453,787773798,849931824,653624409,540801865,896305252,311627884,311353782,749807471,815789362,433600585,995569712,772679896,367615301,139262158,132367458,490542871,46017837,716668854,131502957,468186149,158731595,164440658,748922246,904084055,489587701,699743134,220157207,122471859,831655728,85887339,865771587,202584233,352778334,793115678,128862427,612389871,105557500,892488325,582446455,557888993,270255334,970245763,425109864,58228062,503530900,719014646,187382610,176472575,614183505,496495818,349073503,810289771,726475578,848859456,255006590,49803597,470356640,86664511,351683653,999868757,592349787,187482771,233537457,567594234,806327413,866437123,813975105,340378234,429091157,492203912,848668717,762378516,265935209,590707283,298788300,961123168,415667977,224287083,619904128,291187819,560764958,231974333,966091812,789489115,811300553,530285413,857331262,611958269,46938069,396635079,332380609,428269030,516040344,148571873,670316046,352949288,141598148,515746907,774725241,66576271,228197428,282214568,359205361,202454556,623876270,544534335,344918856,677483925,81286108,257316678,176866174,365751992,331653291,623420522,3755796,43938460,835985141,282618993,588813912,785513801,584779926,434146769,368581979,650483022,763096271,137664226,557363145,398081259,6379075,384798167,877292107,409995296,423968489,492608569,910177562,491278752,791115840,858674836,986238161,585887448,891096458,372463716,545383456,739307923,516003800,997849463,462475895,169384491,301733020,374654974,543483938,177258634,586673966,475861007,970619657,119030694,522912094,184698075,824099846,326025091,954065512,143979859,685885467,762265811,933142224,818901568,501454058,358240417,410638636,986303442,901609173,284602749,265869385,752779087,470236196,967800702,874068159,768919056,688931160,988647754,572108505,341437374,420282102,131982064,128697588,118765576,568989166,797980922,158526255,586573562,407332483,10192637,993086910,258625520,52374663,335641988,301222599,713678207,356847353,406382282,403378417,986594758,936541235,340217586,797560575,378936073,59845328,248168311,205789708,380529227,989326871,92856553,877452075,323301772,736166373,894363907,506006508,923194908,822364577,764240909,444610427,982919074,566177950,317925187,843018044,644494899,228399224,411637826,714373247,503230459,671505098,270425835,992637909,175056043,345719038,69905397,210876664,304700196,552302676,322425037,256874611,613925066,314447349,817555362,378406021,360742015,529541756,488606984,569931901,409862861,158897404,93715110,607744932,442843986,756051441,141506695,889687921,269064185,653019039,995702747,963849907,169682404,610756807,376621728,344863768,258059901,147578853,595699290,455097082,202663605,902327078,365405657,427780734,515146974,40357484,614797403,510874888,939709942,567958371,520243864,73821706,709487933,875151464,77557793,594256159,429929884,854124166,937129734,777783380,594504546,757057988,768428135,172718886,372684921,899517480,240600554,996149160,489606088,469864427,325669806,206961087,185555903,875771872,351238677,90466296,328966691,713655503,175168110,113433387,503732932,739252743,180446394,273275303,426061521,518610229,446401603,524428509,330321842,778085380,838416963,270786972,561322555,968479569,822249656,726862288,359278006,589114935,852444259,654534364,951175219,148450836,26811826,855543545,459548139,635388706,310529012,368986310,669524822,688080702,181604517,183689924,723161684,941546061,702466750,289611614,496820340,790820866,997105260,922425945,555143643,799432742,854870378,180231806,689274406,266451471,913126263,763103614,989281296,923284223,831571211,64769180,266869793,201947998,694789918,116944597,759181847,588371605,138824955,230686364,105724779,643341,15715672,37481173,677111154,65322060,188489265,796572828,206966884,403342554,869782080,669636022,438546418,995896935,44408609,603031087,641447506,468315624,329644443,435164467,351208187,612332103,446570392,643574562,731210651,407900538,901617305,247209943,725017570,731528160,638405646,806038554,196765182,256607199,326624853,741801569,617216318,299992875,504339148,749099232,840744417,282474600,808959208,745199866,287399633,420776424,326340866,327722311,932367839,130737314,790564718,339563677,416108318,262002682,239529958,861828215,378694667,10602687,906657090,480218301,324127153,724845509,29091526,405392840,401145690,92688409,184444090,912268271,463497126,7941549,44863667,302224994,235612746,989637163,566763895,536771284,18758843,178335455,44962255,952056151,144327404,328012370,470847502,448431023,744262942,492173832,11747901,672462817,245940757,984906496,436504718,755578214,331466141,138217587,574532736,972542353,540161132,148477783,25304067,70270801,942038971,209440806,232678720,134931372,911779630,7562338,106627672,532968539,869135051,446775629,182337880,839984314,527873914,901217927,696740426,208759995,941277652,767061949,613254030,848649469,211842536,374754409,79748800,219250529,988542439,124460029,533244475,969926315,716713108,117572801,230957646,86667211,26223817,668896269,233214184,435639218,456457813,596905274,938455642,531562233,83014071,890443456,710354881,651633490,679571858,439610780,228568896,955843106,741946623,419406209,258218613,678758277,535033420,256662930,240980013,532777861,657053757,699244615,831252491,35785682,682177085,862313501,426241680,558026495,233224286,729760200,215494818,828587889,239167060,356614100,105790928,403916358,294028182,553658363,367693003,813477328,36423018,278263727,105965662,499579088,153349473,186842461,492084688,107506713,323791027,231297212,685531839,238949449,776637243,880321091,211074163,476788576,722987662,906866147,764232458,505133390,479300042,291305792,311716676,72624072,334649248,650273310,771820277,257889267,710765678,347473756,961044844,356050589,209831110,632161867,626637870,86404925,368402172,997987248,157335655,521860458,93318398,373108756,694881683,974507443,1622106,428215801,882246949,527695499,703781566,451803266,647171386,21941607,683242284,704393155,577446673,746091667,693593710,635779046,758820440,544175441,638730194,338348970,369326491,546502137,534256688,416362404,20012067,321680989,841949219,457934435,718483826,101248470,579355647,824378143,551534365,532671947,397692517,500217776,524116646,910801078,380277370,423164663,935944827,6797781,141629099,479759500,855689045,117242932,523460201,385366290,3701274,709000695,639369395,1342409,758682654,286712878,652028257,441456613,187780038,568807976,837349514,376066145,635929646,814236936,893446298,584027149,169032963,594548297,583580323,495541860,869006252,674513752,300476127,309619679,622607397,337317908,660572023,251721685,8912343,527637067,944354032,944495059,464697858,549158683,370258797,391110492,148783991,195263544,767420415,997456315,555129863,891113616,678566739,869468772,684939745,30458767,918030800,244166715,744169998,736146507,376388135,575570984,900761346,609367158,345081895,255661700,59889517,728308626,898680963,226183884,477899946,366206589,513766119,622776880,369773890,970387943,893195117,339108413,854183139,291176009,839260992,938503823,795266189,269164824,370566310,889887271,570242007,390748512,612651438,725391484,444279853,79469864,302095515,391478773,103436666,281636356,40108283,880514043,204701423,509442874,802408490,804650501,371566198,516099344,265902308,633940327,891831500,753849308,627844492,280708215,56470511,640746128,791038214,574071622,877907445,414531454,678387447,918000810,624890066,947767737,147876833,257706896,820770669,730465040,724206355,129904320,541501466,713040126,243892920,124670698,169045701,351735643,214635712,652341396,172377282,202012728,364195245,719381928,280101385,577701175,86241934,52289237,175941789,18015096,282832432,564781377,887010351,625021310,36131481,91898582,889186356,217717272,779345444,619420663,647398575,336056250,773547480,22977653,806623531,101237192,524312600,729400706,794647204,165418003,612627560,27589846,289047155,699748803,49910399,16904307,967671683,674015891,510614150,9670132,288935526,680629016,898470070,210509049,672598283,135193551,191562157,710000672,703734213,932440961,945928559,640958624,22607077,710987206,169716919,123983130,736690775,775158016,555279669,661652947,291837002,627716257,93241185,156759677,195628034,381236496,929202252,357189914,211001474,868882013,427440449,623177885,316292912,931212338,777043633,274577821,536213100,296084895,239596177,287621627,198229997,817373695,342326435,552272515,442754975,28716650,317255941,233033587,410777136,804149066,527334832,47663225,642291555,710818570,874576302,607544995,556507447,528901146,474674223,619929507,140502899,462394188,211660059,60274720,599672724,681109035,400630278,634103707,818278669,986563752,737098594,30959850,512173300,463274803,410630894,509300222,408329899,799563341,155721609,318164454,418812648,934087783,116713615,666481567,431343799,7765918,516863257,589075183,938895774,770823941,501410792,240746363,187736516,303682542,476653520,432628920,413919792,546634569,299087952,601753051,618843058,333244378,315049483,345900801,793784926,175543627,364098872,727679176,384949256,696170517,417433074,146235752,526258066,686521706,739963263,593982149,591050999,254348542,702914471,938714392,10579607,515732742,867708561,410278879,924595477,233707226,587900132,939699047,197137829,246932522,391551149,703355036,617878629,186740161,564002463,231977898,493887163,116115677,280218466,170413184,218779233,849109004,142921081,161145534,20361462,145432232,591906246,27630750,170389662,783817058,175611384,967338446,651880158,284733303,918438880,652869738,711927730,619022677,448280825,482596142,430193068,641796499,346138718,391663479,758048688,296839193,769468997,820212560,591200966,836350810,265308204,43311053,784766846,109916784,631440516,394998453,603915060,856392761,971209718,781892395,64737279,683131145,696665912,84403801,430621575,933874640,685958907,426998517,624664852,764606474,978289939,623058228,147314235,294244999,941833369,65651773,458138780,19178082,303398474,220369148,610345760,67654989,806893283,450916831,13820299,701289333,792933344,848484656,511170270,815633807,616844299,138151979,67594832,71229122,469465289,316968771,759047640,42401900,903444717,219572045,725793780,769398288,139784574,199037145,610972207,522546426,568351822,625677225,17435162,944944563,711996688,710225955,476276232,689487794,854085530,803234105,297639697,588307026,86238001,647486615,778649943,871280098,77846006,11376644,182966598,268688235,844671948,522355042,173255656,206238651,546568969,49471069,230426072,647123113,709990339,33042983,337734887,68497698,546877891,129799519,53982182,200318095,909988866,527321362,971986196,80807364,251423598,39546868,613406257,92327817,386987580,586055717,666111336,851189999,670376812,89095542,533464096,401917649,382271108,745325510,583002609,817566165,493426521,847063805,796595243,136774500,793241230,903974966,779211342,911149954,542859178,978902351,961216414,512123029,990947044,354508222,766455328,488410785,998130413,573513932,908924850,983446082,210754086,562058698,813199343,226723730,724855541,614969533,496173178,958212524,746987768,771760418,105197521,255881430,838035952,573295480,200324207,219175086,800839085,176314033,909772918,936431088,152305306,356124530,361923812,787756165,729246228,650218986,777340073,870978930,965633591,653998898,30793684,660774681,61250610,165290102,67518349,742428555,85566649,710395153,154036379,991763157,874873738,289549620,55836750,599637459,573728321,827428017,528645275,204543345,743654603,861917126,317149718,953913460,774710426,600965476,120057746,714780047,49261505,166658,317938767,95258846,747303938,238798365,731399395,570774064,671411,135517135,565527392,374626710,494565983,236254410,905712596,909403036,561628438,21360582,907620390,168997845,270086756,343216410,487181198,286060871,501690421,459664866,978359592,721480066,953143708,757034901,698678547,5517104,64215904,393672024,198959833,743700673,398220125,610408506,479024100,196335629,542856706,573605979,891196010,395822946,571606184,971949655,885647588,91269188,338862875,810530865,640285464,650848102,447495438,495956559,493553694,350906975,261118770,594244212,662416839,720184520,747495615,42858689,783845377,798900390,604850678,535531762,355258850,943528802,68126466,953261638,400622470,962426382,310037247,498315705,336738137,513107116,695370797,659674271,293488843,184549278,455295213,857982171,37652734,246771599,470271469,398716573,957278417,371560645,499207120,537248582,509749007,861075452,235427582,352785947,319951370,641309758,773747213,674298920,312097232,574308079,903737535,243495620,165520987,303504215,806453512,323208615,495376785,994133291,19603880,624219271,620399574,715491697,8943876,405130267,29917935,627920072,170146410,454398479,818028434,4631296,191274509,99954875,581863674,203951551,530514707,320800218,69960623,608096023,194028586,173803073,657660899,464844015,591960575,68867489,318148430,350060072,847480571,856437366,930493866,756115653,365749873,461143255,695445211,543945870};
void init()
{
	for(int i=2;i<=5000;i++)
		a[i]=(a[i]+a[i-1])%mod;//处理前缀和
}
long long qsm(long long a,long long b,long long c)//快速幂
{
    long long ans=1,base=a;
    while(b!=0)
	{
        if(b&1)
        ans=ans*base%c;
        base=base*base%c;
        b>>=1;
	}
    return ans%c;
}
long long sigma(long long n)//处理Σ
{
	long long sum=n/step;
	long long ans=a[sum];
	for(int i=sum*step+1;i<=n;i++)
		ans=(ans+qsm(i,mod-2,mod)+mod)%mod;
	return ans%mod;
}
int main()
{
	init();
	int t;
	scanf("%d",&t);
	while(t--)
	{
		long long m,n;
		scanf("%lld%lld",&n,&m);
		if(n==m)//特殊情况,因为题目允许二者相等
			{
				printf("0\n");
				continue;
			}
		if(n==m+1)//我们推出的式子是必要满足n≥m+2的,因此要特判
			{
				printf("%lld\n",m);
				continue;
			}
		long long ans=(((m*(n+1)%mod)*qsm(m+2,mod-2,mod)%mod)+2*(n+1)*((sigma(n)-sigma(m+1)+mod)%mod)%mod-((2*n-2)%mod)+((2*m*(n+1)%mod)*qsm(m+2,mod-2,mod)%mod)+mod+mod+mod)%mod;
		//长长的求和,最后那边3个mod是怕出现负数随便写的
		printf("%lld\n",ans%mod);
	}
}

因为分了5000块,所以跑出来的耗时相当短,并成功地骗到榜首。
相对应的代码量就上去了…
在这里插入图片描述

后记

其实昨天比赛的时候不会分块,推导了半天最后卡在 O ( n m ) O(n-m) 的算法一下午…
分块与其说是技巧,倒不如说是为了卡时间的“歪门邪道”。
最后,感谢各位能看到这里,若还有什么不懂的或是文本内容有误,可以在评论区留言,我尽快处理 (咕咕咕)
Dr.Gilbert 2019.8.20
顺带一提,数据出的还挺弱的(手动滑稽)

猜你喜欢

转载自blog.csdn.net/oampamp1/article/details/99847537