考虑分块打表,块长取 500000 即可。
#pragma GCC optimize(2)
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const int MAXN=5e5+5;
template<typename T> void chkmax(T& x,T y){if(y>x)x=y;}
template<typename T> void chkmin(T& x,T y){if(y<x)x=y;}
ui tab0[1001]={0,1786531,3626619,5484949,7354783,9232990,11117795,13007978,14902767,16801511,18703742,20609121,22517334,24428111,26341239,28256577,30173952,32093208,34014232,35936952,37861249,39787032,41714251,43642806,45572678,47503753,49436039,51369460,53303948,55239486,57176045,59113583,61052055,62991435,64931693,66872779,68814710,70757483,72700987,74645277,76590321,78536076,80482483,82429589,84377381,86325858,88274911,90224615,92174917,94125775,96077254,98029311,99981894,101935034,103888691,105842911,107797602,109752807,111708528,113664709,115621391,117578528,119536106,121494147,123452670,125411579,127370936,129330713,131290922,133251543,135212541,137173974,139135746,141097978,143060571,145023480,146986804,148950456,150914494,152878890,154843642,156808703,158774172,160739935,162706054,164672461,166639212,168606281,170573657,172541387,174509405,176477690,178446285,180415229,182384402,184353925,186323718,188293820,190264170,192234772,194205692,196176880,198148346,200120050,202092028,204064296,206036780,208009568,209982518,211955869,213929375,215903123,217877128,219851415,221825854,223800593,225775580,227750809,229726217,231701883,233677762,235653848,237630183,239606743,241583546,243560559,245537749,247515176,249492772,251470627,253448715,255426956,257405438,259384085,261362948,263342041,265321309,267300807,269280466,271260331,273240383,275220597,277201069,279181684,281162504,283143496,285124631,287106057,289087600,291069320,293051234,295033287,297015549,298997996,300980614,302963412,304946346,306929518,308912798,310896231,312879882,314863695,316847636,318831732,320816061,322800543,324785104,326769893,328754826,330739920,332725178,334710587,336696165,338681917,340667758,342653804,344639936,346626253,348612743,350599359,352586180,354573033,356560095,358547293,360534632,362522146,364509801,366497585,368485516,370473575,372461717,374450105,376438532,378427208,380415945,382404839,384393851,386383010,388372283,390361732,392351272,394340957,396330799,398320717,400310826,402301008,404291349,406281819,408272394,410263090,412253965,414244915,416236026,418227251,420218579,422210009,424201570,426193291,428185110,430177067,432169087,434161283,436153602,438146043,440138563,442131229,444123980,446116829,448109889,450103007,452096219,454089561,456083048,458076580,460070259,462064049,464057942,466051941,468046087,470040355,472034670,474029114,476023696,478018324,480013094,482008002,484002963,485998077,487993248,489988551,491983996,493979472,495975105,497970806,499966611,501962547,503958510,505954709,507950861,509947215,511943679,513940218,515936797,517933533,519930352,521927288,523924283,525921403,527918633,529915924,531913332,533910795,535908434,537906097,539903919,541901801,543899790,545897923,547896013,549894279,551892608,553891059,555889594,557888250,559886988,561885747,563884652,565883617,567882700,569881823,571881124,573880501,575879889,577879410,579879056,581878750,583878534,585878388,587878355,589878421,591878556,593878724,595879056,597879465,599879921,601880551,603881158,605881888,607882670,609883550,611884570,613885609,615886773,617887989,619889318,621890665,623892147,625893634,627895347,629897059,631898845,633900762,635902674,637904731,639906823,641909001,643911247,645913630,647916006,649918563,651921176,653923848,655926549,657929419,659932303,661935233,663938250,665941421,667944610,669947853,671951240,673954664,675958178,677961719,679965391,681969126,683972932,685976793,687980754,689984723,691988890,693993040,695997243,698001534,700005920,702010408,704014917,706019522,708024196,710028951,712033729,714038649,716043582,718048615,720053715,722058862,724064160,726069456,728074842,730080253,732085770,734091327,736096968,738102711,740108497,742114356,744120292,746126319,748132353,750138460,752144639,754150904,756157297,758163640,760170094,762176673,764183227,766189926,768196616,770203372,772210235,774217158,776224176,778231219,780238348,782245518,784252792,786260048,788267470,790274882,792282379,794289928,796297569,798305261,800312988,802320805,804328692,806336668,808344615,810352701,812360812,814369015,816377245,818385597,820393939,822402368,824410845,826419428,828428007,830436690,832445455,834454294,836463111,838471955,840480989,842490017,844499163,846508266,848517571,850526802,852536098,854545524,856554948,858564484,860574046,862583663,864593371,866603110,868612866,870622738,872632673,874642675,876652683,878662789,880672925,882683151,884693394,886703646,888714049,890724432,892734982,894745528,896756138,898766718,900777399,902788159,904799071,906809912,908820851,910831805,912842853,914853985,916865085,918876299,920887585,922898870,924910217,926921650,928933170,930944682,932956259,934967918,936979575,938991288,941003081,943014928,945026825,947038803,949050806,951062857,953074975,955087089,957099319,959111610,961123925,963136308,965148758,967161201,969173750,971186285,973198902,975211587,977224323,979237141,981249951,983262860,985275781,987288724,989301771,991314862,993328031,995341225,997354445,999367709,1001381057,1003394454,1005407887,1007421390,1009434916,1011448475,1013462088,1015475816,1017489503,1019503328,1021517198,1023531037,1025544890,1027558945,1029572956,1031587026,1033601168,1035615334,1037629530,1039643796,1041658117,1043672466,1045686837,1047701335,1049715881,1051730384,1053745017,1055759631,1057774316,1059789087,1061803891,1063818731,1065833553,1067848543,1069863463,1071878527,1073893603,1075908701,1077923824,1079939108,1081954356,1083969663,1085984978,1088000351,1090015776,1092031278,1094046784,1096062393,1098077938,1100093695,1102109387,1104125101,1106140885,1108156779,1110172648,1112188589,1114204546,1116220556,1118236619,1120252680,1122268842,1124285102,1126301362,1128317637,1130334001,1132350325,1134366721,1136383244,1138399701,1140416251,1142432844,1144449452,1146466146,1148482885,1150499648,1152516476,1154533287,1156550201,1158567162,1160584157,1162601158,1164618217,1166635286,1168652459,1170669652,1172686855,1174704150,1176721515,1178738854,1180756260,1182773718,1184791164,1186808732,1188826316,1190843950,1192861532,1194879240};
ui tab1[1001]={0,23534392,564829332,4265370305,1659802436,762848986,1247181211,2732800404,584392940,3513574090,2476282454,1342957244,27689054,3013769009,1981117385,4218533371,1768724149,2891732274,16316239,3472626002,2269112597,863311925,2333748430,2488540554,2004652246,100038607,973090609,4071787386,2721386430,85918709,3658243291,689308763,3119760004,1790866305,4029529587,1448154464,720381673,3987011076,3720489777,579812194,4022035537,413346736,1929101980,1303117665,2223094732,1473883333,3097579295,2064386178,2030239581,1190095124,1747536492,2655199738,3907617216,1929989545,2306453581,2356018516,3267311780,1303026860,4042388843,3709077851,3520924137,354684988,3356115678,1371773786,3546675087,2103771623,3807591322,2637948420,1568671388,964922016,1239495250,4121244122,2911481537,1432058236,2469298648,2817031804,323762614,1435131832,986520719,3078563996,3595822530,4015706234,261534352,2284727546,3900877371,2386674215,972454540,88312059,3391776732,3786535291,2323957240,3830662665,1101799101,4089210002,2482324573,3633283341,1599468398,271500783,1705901055,4279622574,1591633218,1576927376,2237983501,1151917532,3369533382,2331307932,211683575,2759182309,1995150116,3142268955,4072522432,3426612437,1747294670,3239130892,3889207975,2900967279,1302139815,1221857156,4153478179,1235698519,489708392,1577358894,4199089107,2682409151,1725077674,3465475564,3852996132,369304508,2761815469,2954069751,3514176303,2086530139,3056363148,4257230536,1689145015,1247976184,953799595,2555672788,754813135,1585021343,3721010548,2826660724,82246689,2491727933,2939197919,294043530,300536673,2713450820,1099832513,2652408819,1491178414,1296945536,2677236679,1807727486,2712415518,535502488,802913263,4285269643,2544431464,4096848837,88021170,3340612185,294308187,2440394896,3697724333,966500286,103771519,2335411653,2900376567,2349046848,1751979484,3966772391,4009187209,1857506439,750960308,1320852186,814263007,347719892,2039865159,3987300531,1908465587,520813160,2692265482,3362962390,102289864,812533187,863459670,3518254042,2944551987,45359873,858256113,515724058,1328963544,816203928,68019572,2973229151,2155345444,1941750277,3980642097,3032769655,343130070,2282438319,2512373611,3752126798,4250217345,50998041,2356906659,2918812658,928625644,1043841765,24186473,1899906377,3415896581,3379807875,3090190584,4287961302,2313879876,330578727,2445339276,2849750229,996365468,3236511539,1949074984,604546652,1345183597,2479584173,1908833909,3526229364,1156077554,653823782,3719551613,980339178,2424829423,251196036,823398462,1923255720,227252040,3383082718,691489643,4232760058,1092580680,3980068810,2610296010,4220671111,1748706930,2974183511,3328859531,3298830570,967052424,2663548206,1093689269,3007334192,394027592,1296682770,2083457799,2117305437,3774833279,1738507811,737082005,43946556,3063235227,682144877,1277380580,3320175260,1064796382,3081587639,3802716670,3932530160,630917424,1912004556,1577784751,3765883724,1372717384,575999726,1910168632,1862699198,1142915907,3202309799,4077244809,1572541461,2410477981,933560024,3396845517,1738232295,3480790960,3501233678,1218594637,113282708,3062288027,687480026,1408719742,1606892616,45924467,2015382521,2069479843,2933178801,2344317443,551682607,4076311050,957496415,895942584,1112952884,534848205,258801149,1664870911,4292833472,4116397416,1057236479,3086242298,1924389220,1732705626,2688254362,1233743326,2560232907,482310843,2948461161,3912096097,1152296672,1456121097,2088630258,6151261,787588384,1812813440,3441971867,1238027954,3592575217,3963637731,783541411,7602138,4280597629,2933842491,865922443,1563259292,1825981154,3196453515,3751684255,3941795203,1772316205,161629506,3162658445,4146039046,2655641225,3731500254,4062532325,2670775195,2030610453,2634234614,1364908732,664416500,826755374,2059249720,931990721,2479949018,647774906,3267956703,25191491,541604713,2452776926,2305308680,1045186858,3020141776,3586120789,1639308601,1995313833,1624891918,2051457842,1220661737,661838992,629820366,1994088838,2313343471,2482379693,1241325769,2632606366,1362407834,4283862894,696533763,200185481,2985547679,1276315496,2984241391,3113878297,2637035046,1052085589,318723526,1535363933,3887580291,2837412217,672391607,920018793,1825446199,747730551,3485414013,3155995470,3186806511,1622414609,1266040810,3313388481,3672954229,2107319789,827555021,2830871918,2413454243,4208165722,1091156312,2418454871,2307865317,1773394290,847767474,4133825650,4082273541,4147894738,737034359,1169617165,805998606,1701401479,1504541707,531106639,1009285906,2659692499,3548575831,1820956684,555475321,3431641120,1582125140,3139644510,16649747,1954613725,2368917060,2912640315,2427264779,663553597,565929914,3721625745,1832332202,3622934327,1183609137,1975308420,3048753944,3451666693,1263590650,4250828381,2848799663,669464886,2479567343,2225118457,832333375,2250838847,3731864327,1173311375,539815190,737971272,1849963847,2807130798,610698098,2085042524,1804769456,1837216078,1677173834,3972919717,804384807,580725019,3166854910,3388990242,3656791972,2625011887,1575572741,1283351450,3262377477,126864518,3554917638,609011060,2055083449,4130427958,716178866,3265892039,2403598717,3942821458,2772101545,2174481459,82550077,2867630299,1101973063,3495201812,3952026243,1091945901,214345749,3015404921,2998102586,734338348,2479372743,3144809362,1481324779,1273740907,1871580096,2634226415,3171834573,627010938,4162145590,875435680,2170232284,87889788,2630811961,1633624820,1338332460,4239821457,1522418535,2404571452,216143064,3632641917,3346228686,4292681472,3557726352,3214555428,4141402456,3879234514,2112965270,969125642,2847239993,4289725938,3876169256,3188478157,930000605,3240884447,556258992,4199297495,832580376,3745327353,2359328499,3758613745,614176032,1332182986,4076396287,2284048205,2372235848,2117759170,873448328,2700283873,2318631059,2731434882,1581245930,1163019876,821955625,3182010005,316723614,1155063956,2900585615,433897158,1048738285,3158249210,1487228189,3500006011,2914872855,1543045958,3494588887,2848316315,3211034457,1162227245,2699145490,3741711102,1218128123,2152815962,3545813948,2464698810,62819361,4166885333,2181004143,1031768454,1702470713,2775135808,1877636892,2018192352,3829611866,2061620245,2288587127,2195794982,1073269225,4162282860,442107255,212386585,2341783121,1165654860,592459941,2456193521,4070999836,3960419815,643613973,515892729,1640838179,3071440750,2549267337,3787899583,1056046571,259931618,2886475937,1277779682,3521445551,1000991407,3765855248,4294146367,2157335784};
ui tab2[1001]={0,2043702206,4207717174,3810154023,2823836762,1507037206,2395872277,1309263646,1714253610,3434607906,2492160918,3339788528,1552222408,3414080385,2611822347,3171126843,1003209147,2266181512,3483136115,3481722610,3143694425,1868014941,299201402,22551988,2551823416,1718871541,597672281,1904052322,314104160,888166371,14234567,3430787457,1687007890,1593223087,130205309,3704477728,1199583121,636386600,1883510613,319915052,2125146761,496044174,1609939160,1621757227,395300244,1444410825,495973437,4038282414,779797495,3343660816,4006880146,3533613356,2892158488,1453885065,3761253825,2865177232,954659766,2327185356,250989301,162949237,1736724649,2643759202,1819925724,3519859522,2078811449,1726276601,1550548284,3975303604,419706426,1677871662,192428018,2047170980,4282772317,3766141732,2209571000,3487054050,2370913166,674952660,4182236205,4145256438,1751907410,2856923696,1756649982,897126992,1495148203,232683433,3383206370,560412573,3397740040,2273028875,1357041828,2187269833,1194199531,592411314,3457534009,2299887281,3752162936,2264814145,3113235659,2179057842,1667914312,832127048,604732167,513149718,1320833038,2194436280,1971156763,3263325893,2962853508,3921652835,39935920,2504945513,3348759580,852510960,2662622147,3880231109,595459169,2979184738,1920579865,558815073,2256600220,1029505714,4280918857,614098739,3051312748,870837840,2942757620,3034532278,1041974623,1511712557,1590541545,346035151,989447490,2275057792,1020507711,3965626914,4052291949,1271051860,1213024329,3996227989,2065619124,341393790,3867487003,3529285567,1508431075,1306779176,268175521,689577222,3330003533,154348447,869717740,3798927482,1611496023,1967776950,3775026946,916319344,2144217625,4119576741,2942704458,663123267,3174518690,1478262857,3323921509,1337472602,1678906527,3835509632,1935425633,1534862475,3492215023,208896314,1617731702,2429173715,3430219931,3980491265,982939362,257527816,1822464431,2123934956,952822887,2175736059,414300555,290396818,2379669518,2226544734,2638003462,3042377079,1947209918,3020185872,2534003955,1522501675,3559094241,673492770,899988918,1682464426,1488727278,2330314607,2727288540,286756695,2676377017,2446731017,427263988,1251913521,1066434535,2154016058,1916957751,1460657701,3983591193,522236930,2792940252,1663296729,3995936253,3833121239,4147378345,3127654919,1472921304,1805419376,2696605744,3596867791,3545608124,2975557415,3730941712,1448381981,4186991096,1620749164,2006182487,242069025,1674987525,3129094840,96582918,708446046,3270348271,2167398914,3191477165,1970545424,3835928412,1829383542,858759334,2667716794,189472269,1343888374,2956855688,360438400,573564234,2441955519,2069959304,2079206299,2635957903,2612511168,1750594578,1264303520,2481445373,1282134496,2155902432,3889833394,302201985,3160245355,1926326569,1619670743,42243447,2985909470,1198423965,426759059,256421184,918436024,1783930548,2117782193,3473441350,299352420,2121956,3830462980,184820317,2834474648,3677208930,2614460030,1988533148,4166909630,1142995205,1374231413,107148247,3214350305,3634689973,1840699924,3997552931,2499712067,3793778362,1832748930,421259927,3605053336,3637362599,2425606974,291313636,3512299564,2582366107,2299785539,1288389037,2000904543,1227631779,2140955613,2034995274,1249895127,1683497830,291278688,2492126435,1446395901,170496139,1211351736,3435272752,1468950999,2963641706,1020837748,3126390998,2051677954,2924478820,2733620475,1730480509,110673131,3914056159,1389773252,3275687407,2063089170,1553941557,3809710498,1938343788,3212250245,332726936,1730275255,4038336085,4081562355,1546333512,309647829,4022601817,2696583985,3110050534,755438924,1612403669,135654649,3230903279,3637653143,107620140,3939770937,138297476,3103447537,63344090,1166885323,1747775301,3304928177,3999094184,1822768898,2093449350,3738934482,2993469846,908673467,1476726762,2647482456,2876288159,121345297,538204133,1360249038,557603040,2318618202,4018183368,36208979,102639495,2117387571,4134173826,1542212922,419831361,2521089218,561010360,1927382770,3796197055,1600668625,2053480797,588008680,2413155600,3583068576,3968375947,1306803673,2559643301,3667042464,2292191115,1896943497,656190778,781155681,2704358560,1522729645,75006205,2080202725,3603892333,3706145303,1508271779,3235739193,4236700369,67679332,1772216033,4199690167,695678070,2184982331,3588545651,2622099889,870236759,3557162078,3059450517,2730564426,3298856916,2741226217,2383466497,3788540790,3063656052,1104349570,1293317025,1852583234,258685217,3308508913,521915354,3688507881,1555506031,4293857333,1850014766,3760702405,3120622975,190851812,892922187,2060717934,2609166668,414939066,300815695,325661849,4233855496,22049391,2998087769,1417904731,2068323794,3419962549,2340483842,95319021,3639850817,3371239544,534060638,3607638827,809159730,4148941555,2490581765,1472769638,1145106387,1404907457,1772964067,2849896983,2448847893,929754519,777103210,2056025982,3115972195,4085157008,2374141490,3241566108,2779488292,3983214380,2966579090,2462779187,1996866489,1747430767,2679192134,3168647196,4149871718,1048507425,245058325,3140014674,2567180379,2808713186,780792648,966265154,3299922503,391184402,1830276094,4018771203,1236053711,4270609580,4038241577,3685512911,3437556409,4025568663,1800341981,2299076634,2901108687,4057029579,2574403617,2141038365,4118640792,2781611612,1386232815,1831178616,3004478399,397365385,3608578178,3546411227,3547285687,1243206468,885040260,269868252,105914848,3972956372,2186337853,928205322,330709920,4130439093,2131611243,3593081034,2710702610,3619284785,3752530400,3538435216,2132261658,3230201188,1373033904,416052454,742618020,2616013266,3167139723,1779615788,2489024878,2276014271,3438801683,2483000173,3149804648,1239235037,3766797488,524194917,2859361261,1860776395,2461649170,1831014410,761450103,1012535695,1968760892,2291806656,884632076,3103375383,2031824119,712137268,4249906892,2408826226,1737694813,1343511347,3684413636,1100286972,585883647,3656559414,2607815245,1237128872,4208519669,2020303455,2699879977,3675066278,4072197021,464961781,1749013791,3990099149,4213073634,3307117228,1463319479,3461086830,3003626572,163245556,245132499,2740225871,2006013211,2608146816,3035133727,4270732418,745811568,115220100,2200768704,4094889973,3622476259,1905283512,2868302269,2017929930,3809201087,657218043,4118164007,3704407760,1373156881,3840364983,1972590608,3428348613,25152583,1043659897,4252944881,1740185264,1095744183,1830832969,2578526787,2144381920,3926176351,509632916,2168654291,2629457735,2365540816,1102523227,1323819666};
ui tab3[1001]={0,2694979134,1577208970,3643839605,615664954,3897050810,2433557679,422658132,2653018242,2592860448,4143035558,3252074762,721953186,3638463765,2300744441,2248565559,3128726891,2349975754,27759669,1491873662,3740682325,2024421759,2719848700,3656922430,460643786,3167080071,2077802197,386146094,226532366,3889893871,965253159,3999882303,3464619130,1102192545,1215661547,66694394,1123713663,2985850166,2363609725,871518000,1291847121,372622772,234877782,2130783861,2587548922,4110142427,3456587347,1223237336,3237447745,4277907038,2586944324,2534715852,1812242996,1610850951,2752114353,515866174,4200557060,3961987734,1864030005,468256883,4204919285,3950234208,956487794,3088129336,563133445,28997019,2161520794,1585207330,3945657620,3664513958,1222746700,4031328046,2009634375,3969227816,3731026634,1468920104,4012605186,2911204640,2725155629,1583611716,369757698,2139795364,3630535956,2741271252,3233943445,2174878687,2068455472,226033195,1636596650,3905058595,719113246,1334428823,1674642161,1082209756,2514454275,568034709,4027239282,629729177,3150908137,2215326242,3367869370,1160127120,3967121759,1797246924,424394090,2871143332,428152501,2693328543,2869832920,871667671,1244926058,975966033,4067265854,1347032974,555945009,294987871,3060952641,2319601958,2949090123,2062635603,935932868,1789820602,3369249879,3121836423,3620669470,824593494,2039646434,2222848496,894513891,2846954099,400686803,2873738513,1816550396,1890115926,3646200949,728804378,1151272147,3048527334,399803093,3735199259,3300661006,1261443446,467879717,1095219651,1711499093,1234509090,3097104621,568111510,2716992243,2289730073,1258496986,3840817422,1364388803,3516840474,1978895862,1991407168,2809492285,3310512593,2745075408,425714285,2260141570,1070598437,858308661,3554473180,1324549441,4248432408,3559497737,4209525249,1722369201,2655809740,372080292,3788066791,2902435901,1729399383,130840596,246064674,1681956413,2535972754,3339455855,3491053915,3885869193,3291608218,307051304,2675017408,2255447308,3684389293,2524603168,1750285528,1512668233,554152049,2720246089,1915064636,1448187884,1943016828,2764703998,1669209399,2341576046,59623767,595186757,3718002041,4232331182,1527830559,331891739,186025504,4119647363,2202344387,1358598883,1835905912,1866993904,1105669387,3535719425,1321086057,180744771,661172835,3486534962,127715100,581175272,1925494311,2151954152,2264717741,2125605030,3881053151,3249744612,3827192694,2561693805,2473971053,652300935,1069712482,3814456524,651071972,1631078573,1241913116,566249769,3863168300,2923410048,4090412802,3555130080,3117585832,2126016935,3940319760,4172406356,2998910934,2983996070,3258579349,4072919846,499400489,2259558499,3044407776,816444924,3012473232,2985121775,2321279008,2467566566,1764947850,1439782955,3987099237,153760501,3365889463,1400826753,1171660410,1973240223,907504079,1987859930,4039312346,1020321534,3190817849,1954782924,1299661602,1156655006,2733723908,1717501409,640145390,74885184,4274425264,1466773914,2051669896,611111193,574260139,2386412245,382942737,2866178839,3853829858,587786623,3679085081,2144132980,3650560876,2038617619,3719442682,794880657,174780024,1990467350,3010066190,1431619295,1640924947,1713523749,387486331,1505011221,1256990161,2788465248,2422821171,2178309764,3688740460,2033891643,3017715933,190076091,1652853738,3764888996,2491109013,1828610626,3202347632,257484098,3831157884,1983279052,1672452863,3501518785,797290909,1580652105,1953039012,2522124017,3033629360,1564847581,1220130272,1559424972,1457026183,2414447628,562497269,1804937999,388884517,2361838302,2825281441,1833056373,4284466893,750108294,2453024252,2331222823,2815683063,3175437293,585912777,1802988462,818329205,1369412622,531381707,4229229614,3359141413,1979527087,4256243355,2263685638,1754915470,3328721908,3465586652,431420576,62250543,328715304,3966680966,1621622749,1666458437,1865761617,193952726,1336114240,3963268176,2198762102,1722626913,676232971,3938439409,1678994828,284033978,3893994259,1751152524,3985968418,1817932280,3866039065,855001217,3009855171,676008680,2663976680,3458924742,574670489,3740786757,1238179471,1583358376,3354382151,1851271235,2062645208,3522642887,4250182026,233037797,2485024103,2540089543,751229025,791027111,1296297423,603111165,191641351,3403320424,1374383265,3578458147,2661550254,3066925471,1369296903,778065371,1223538341,1845444810,868216531,1138759340,3845203480,1576527191,3488076983,1869985102,1700463140,481851532,3197286719,1140366288,206146471,2594513469,4272525972,2228701945,1395618575,393074793,3348031992,3283445753,585455471,3293390384,3084602281,4217972094,4184359746,2254052336,3033276259,2602334299,2488477598,1307220909,1360599009,2318529923,287902478,1033969643,2459590746,449404059,945504589,1887938088,385610112,2891757735,3754604020,4198402245,3753299867,4074830704,3215907035,3298062541,301470681,3670996257,3467980903,3055640837,3002611334,3496475252,3656139289,3861180354,3531528448,1873264198,1897254586,1352077262,314006120,2023315937,1528425799,2117510959,559931632,1822387212,2524988126,3194763357,2003767581,1404175466,2552486951,3834263486,3429021088,441277892,2865560161,2506978946,3423253212,3857142845,1074015689,1569746820,1981056463,3901352703,191742953,3046843191,922885875,2849042468,1118697119,3234376595,3596507347,3435921313,326536990,3455565114,3384810921,942689404,2078739395,1863405467,1946822166,608639613,4127483249,1645546314,983095672,3366531428,1186754710,3930797914,1686770857,2558954590,2964758922,1400505183,2384481871,64731380,2675749356,2866176569,1160008454,4034870424,2397260470,4293204868,1405169500,1644121492,4161159266,2579544548,4183963975,3009665238,1977058012,4237888543,3921999007,60544401,3892670870,3338916309,3118764278,2272597949,940960467,3344784895,1323890050,960618712,257916781,866113885,3646674922,1746103684,3995510054,1822564529,2944190843,772770380,1696218316,2434497070,3868783147,3827833427,194651478,1597580054,2880677537,1515941420,4210648975,2899816950,2052492503,2543918391,204070861,2333988412,2793234635,1793611947,1178323413,2476579121,1172727566,2493307708,4184415621,166961518,1031952790,3161454802,31760083,118122687,1891192257,4059034372,1470349661,3205857938,1465635322,56523104,212697904,556327505,177327997,3434503662,186049279,1969065702,2615210517,3160341975,2431737033,108556866,3739579,258465733,3764481448,12353007,2894950431,1073469645,3600089125,1267996352,1714116003,509248899,2371927533,510894426,2656748387,2365444346,3873413093,772301885,3837838884,2778067197,2682007236};
int N,A,B,C,D;
ui pr[20005];int pl;bool np[20005];
int main(){
#ifndef ONLINE_JUDGE
freopen("classic1.in","r",stdin);
freopen("classic1.out","w",stdout);
#endif
scanf("%d%d%d%d%d",&N,&A,&B,&C,&D);
for(int i=2;i<=17320;++i){
if(!np[i])pr[++pl]=i;
for(int j=1;j<=pl&&i*pr[j]<=17320;++j){
np[i*pr[j]]=1;
if(i%pr[j]==0)break;
}
}
//printf("pl=%d\n",pl);
ui s0=tab0[N/500000],s1=tab1[N/500000],s2=tab2[N/500000],s3=tab3[N/500000];
//puts("qwq");
for(ui n=(N/500000)*500000+1;n<=N;++n){
//printf("n=%u\n",n);
ui tn=n;
for(int i=1;i<=pl&&pr[i]*pr[i]<=tn;++i){
while(tn%pr[i]==0){
tn/=pr[i];
s0+=1;
s1+=pr[i];
s2+=pr[i]*pr[i];
s3+=pr[i]*pr[i]*pr[i];
}
}
if(tn>1){
s0+=1;
s1+=tn;
s2+=tn*tn;
s3+=tn*tn*tn;
}
}
printf("%u",s0*D+s1*C+s2*B+s3*A);
return 0;
}