[hdu7082]Pty loves lcm
阅读原文时间:2023年07月08日阅读:2

先将问题差分,即仅考虑上限$R$(和$L-1$)

注意到$f(x,y)$增长是较快的,对其分类讨论:

1.若$y\ge x+2$,此时满足$f(x,y)\le 10^{18}$的$(x,y)$只有约$10^{6}$组,暴力预处理并通过二分+前缀和即可

2.若$y=x+1$,显然$f(x,y)=x(x+1)$且$\varphi(f(x,y))=\varphi(x)\varphi(x+1)$

换言之,问题即求$\sum_{x\ge 1,x(x+1)\le R}\varphi(x)\varphi(x+1)$,通过二分可以得到新范围$1\le x\le R'$,这个函数并没有很好的性质,但由于$R'\le 10^{9}$因此可以分块打表处理

注意到分块打表预处理以及计算,都需要对区间$[l,r]$快速求出所有$\varphi(x)$

关于这个事情,预处理出$\sqrt{r}$以内的素数,并对$[l,r]$内的数一起质因数分解——即枚举这些素数并将其在$[l,r]$内的倍数全部筛掉,结合素数的分布以及调和级数,复杂度大约是$o(r-l)$的

1 #include
2 using namespace std;
3 #define N 1500005
4 #define K 500000
5 #define ll long long
6 #define ui unsigned int
7 vectorP[N];
8 vector >v;
9 int t,p[N],phi[N],vis[N],Phi[N];
10 ll L,R;
11 ui ans,sum[N],Sum[2001]={0,24914787,3137086944,2464224208,203189032,3449159140,4033773776,2287331592,2259387784,4278809768,2728034220,1421284728,1632991496,3084174244,3081444120,3479813036,58736376,1679860800,2115586824,3108754724,3659593832,1296109640,3335098080,2424792664,1379875632,2361458064,593204068,2881402460,722993064,717671696,2076363960,3790889416,906330240,2800607940,1446608324,692549928,1935163072,1067888940,637979988,590904032,1279173044,1659465532,608332152,1535502336,1891041352,1501490756,765930444,3889000112,2277096284,711498472,3367208768,1756119956,2889809848,585283384,657621328,1541824876,2194003252,2732809620,2642784300,1755708812,2262470360,4173074244,1251704608,4253370716,209913808,1138383812,1608028812,3240288996,3650689700,2007676252,1496808560,3503076724,1420478532,2720640580,3524450412,773237840,492475952,2310041824,3021947092,3194563052,1439103056,2235569260,3126580916,1557228684,987491972,3915267496,2933347432,2282099964,2048389688,2347962116,3247285524,3184840264,1929025984,2449493172,1347519280,3301416460,3277771580,4228458972,2160296740,2769289536,1457276776,3646623936,803425648,1588459728,3860233992,279123652,2577570756,194733472,1376547228,11272364,4076525312,873893156,3501417384,3951953020,450723748,1283858020,3684885104,3545732412,1311441992,1026179192,4027168804,2749737324,199522932,109500564,824016316,3671733688,1205589504,1183468360,2614653344,1029757000,403044452,3454841268,154248176,4044459040,141675072,1613670140,2876918072,2057165660,1298766740,2970849876,3982962024,1967543792,3647156576,2453060856,1938543024,328052996,3733957820,635240368,3044371468,3380895464,2348222168,2665539572,2279227032,653000548,483855044,1383848912,2352257516,3952272008,2063810560,1033606372,3843761672,2454382692,718131844,1427002860,1145868900,3167559928,1165202764,479049916,940390660,486809112,408060884,2759675340,2101157400,4039138988,2867268088,1130282956,3505777716,4250935036,3754375228,2825192912,2193014388,1306950908,3370560616,3757506056,4101934508,109723616,2146880764,1954985608,3934088852,2566477628,290302200,537384024,1630405460,498563084,2625694464,2863751888,3122712480,3251001248,4233810104,673057192,4197110100,2127218472,2523836668,3668266904,3354131716,906374388,395699744,1385771244,4287651028,3963574652,2310966080,3145754248,2046127288,2622090780,1688157804,2840318352,2966738756,4125028160,1194524304,2538677204,878146032,265327284,3561690140,1224537120,240956716,2294783340,18142320,3142532948,2162666488,1871589656,4176744280,2342092228,1494503168,1506241804,2491449088,1620816808,1504507920,1073750940,3116333104,2046658844,4210820820,3255059492,2268436584,2943830836,1810023104,4015681448,2812312400,4216995760,1462536020,479575392,1365253644,605440900,4229281556,3989340404,2369672640,1852703124,2022238304,471956092,1784597484,3898517044,2934957884,3101303088,1669786524,994290008,228938676,1391291236,4107701372,2548862968,1371859560,3497425176,470257164,2049596044,3986104872,620083528,3408035732,28673192,1641790100,2321617464,1983236564,2139056692,1413031664,3804949524,2761525824,3857187260,3040427352,3625915964,609134420,1196720408,3859630688,1300273076,2119654752,4010984268,1255556908,1226038560,1296837416,2548926608,2278914280,2460478740,3849297380,324477936,3404914960,1194364140,3301021820,1790305284,287053980,2760416144,1386126484,1247822920,652809760,741961584,2128265312,1289343176,2064858540,3580082328,283359668,1576181248,2635144932,828255140,1711311888,4279003628,2455980084,3587038080,2870275428,3428670176,3004981900,3657853020,3835657616,3989420124,3912529996,3754108732,669815272,193507320,2174869520,930940040,2789310816,1882836864,2464233436,691122160,1087391096,2998406304,3358507564,302280220,376019648,2101945764,520386488,1852624192,3967220704,1910237932,3754220024,2422393108,1227618016,3641630452,3041428888,3898197248,2381040524,1854261112,1382770240,1250933912,173717728,3510536320,3369214196,496413520,1747960956,2780502588,3466916252,2006738144,232710980,1651483436,760721656,2699094512,2351640900,524330412,720257472,1953131604,3696431340,2926381936,2880133180,113565260,1500271148,2033464776,3387964668,231261972,2154224852,1963012776,2009177180,3718492284,1737070860,2764419012,307856720,88141364,1838116664,941891068,3785792232,4262443836,1773319148,3518195748,2362353828,204128956,2672024764,457913836,2233916612,1361447804,3350530492,3844095632,2575191456,75190948,1743304268,1822976928,6892612,4032491320,480761124,1407918716,938181676,3973277320,2784324100,4028473044,129560520,2856358024,122863848,2003941896,2107422596,2420617908,3024749124,2249499396,2361611968,3282352208,4254906680,1083719480,3275034496,1736514656,656708868,2053548296,4282660780,325597828,3383851120,4135566144,1303187380,2213438124,885848444,412660540,1882815512,1362126456,1081499140,1013555412,3496193680,2591522432,4012560364,2426675488,437309036,2219967812,2518375244,567483672,3778349364,826456336,3076394448,2202826080,2387870808,2466400672,1905473120,1504530032,1464214492,288969212,2934540612,1707361440,3419243848,1831843788,993455116,3540716056,3499276200,3830778756,319909728,88815712,81024184,2536515404,1906672508,2979546728,404958420,582985424,4092621128,434111396,1845320100,3819074848,2440295844,1659147064,2868912844,3666079488,556467208,1119675496,2141377596,3500763760,719818712,1467615624,4035673152,3369052220,3721422792,3003031244,3919994204,1834079552,1871600556,2885838724,150106480,3146095468,4161862400,3448718936,401335272,1941473380,1990742832,2039529680,1298748232,2311937840,389696640,2095709204,2827941836,535584172,2027298256,1581276192,4267526616,2247116308,1671629880,3421209772,2316289400,3631813948,1026694168,4093052228,1769966780,2617040184,2605172736,1415142460,3035294168,228741944,3247676360,836472356,1573690600,289149112,170863604,882313184,3937908208,4283187868,2707815084,824918304,1379069772,2445234120,1252728160,3880014628,3639783160,675545344,2036195164,315694316,2983776704,1822316524,3500293596,1090072812,4283785660,354561256,2648229068,758546464,4080228304,824555476,1439932860,3063791880,2706532380,2423643364,1929129240,3252073372,2118380216,3393564604,3761136736,1527794208,2864254940,3866007076,1827024216,3175632748,2018659928,2245869868,3075430724,3357124228,3995468936,3319407976,1138232308,2222284492,4284709044,2400329356,1697110424,4146356676,1212712288,472335852,2099456624,2468370292,2405038988,63544012,3635676160,3116566432,4169833604,4064872284,3173397268,1751082216,586429212,2230351192,2538508440,2900820368,2091170304,1326664948,3497474740,3105393168,1854729832,2168930864,3342119432,236054564,3771612872,3671655764,4084690532,1822559436,3751797048,3896605968,827025848,114032644,2988739596,605302836,390124200,1518597816,2690425916,4244244760,4048267552,2494335364,1955978756,3698371892,425336928,1010455792,3413573552,595247644,1762317672,1948782820,1345797812,4043399388,2140597184,487393428,2777433556,801000344,3315941140,3704492600,857446408,1642121388,2559591716,958404472,939004760,4272182208,2822332056,3542362788,2733405604,1506640052,832878056,2987550240,1606678392,265800520,3987730012,2306076832,3443591136,1574081500,3287321920,3261515632,475298004,1462833084,1449447580,2070818084,797499900,339691628,3406813984,1342793580,1545256712,2242203608,1255028604,2203761652,777276380,1869526872,618716968,262137288,3454490996,2668847716,34650900,2422283020,4170974080,63708064,894612540,2938085208,1358016352,2942921468,3836228092,2887181960,1958958520,3520979680,2068500316,3502204760,3514460488,355363480,3944876048,3827187404,2919683792,845549764,2160938204,647460984,1792776816,3135268168,3590588396,2977866532,4245812020,3044911164,3186767020,2214764556,2005028208,2084401364,2156611296,2978406284,2467265136,675384640,3224738568,1562188352,1827008888,947759840,87139488,3150583500,1690351736,1638975276,3704244828,1405042276,1661500720,892934516,1991828936,3905432432,1848429980,2563598876,1882824188,4286661740,3581538660,2670689368,2170040488,3511784656,2222223536,1740494668,2757200004,300136968,945017164,3356314196,4279083516,3728969180,3068810104,2871721432,689897484,2170076180,800647408,3210651572,3861697472,1790451700,4026587844,623245852,277059048,4173487784,1149606756,3366743680,169552384,209230608,1034467604,395630160,1826272916,2080584352,3161442928,3396906156,124332304,815229588,4186480148,2054830440,328418184,1631211196,3870838732,3719343664,1516824124,1849209140,4016718584,507046480,2993185324,1309059956,2629550668,2869444864,1937174164,1599279588,263851512,501479604,3243684164,1343143340,3484465168,2118811716,2299000188,2091938516,1059957064,961642844,391041576,779707144,3571836232,3368792764,144495568,1939801024,3875365140,3583704204,825355436,3357824620,1543148948,1484263324,3367431296,1288422420,2676871220,3163135416,3257775208,1987047664,3302236732,2720278448,1837360500,3400702652,1877349064,4239140664,1354350724,871659888,2958561536,1723637456,1808904236,1477858428,3795914668,2447615684,1690665480,2096774892,147827816,255225676,3995524352,4024953868,1768380828,3144692756,887281964,4258017528,4090977920,1097696680,416101304,4079991540,1075269812,556620140,1295213960,1630183748,2371789076,1140083248,851060432,1386202500,1252730784,361098692,3347814816,1437570668,1909660676,4144478368,1210800072,2759060776,737015748,523611452,3690508904,1704552244,216579152,3164396544,2128904868,1343688628,1368648656,2654482264,3123625956,3296827832,3635595640,3478067228,537273068,2640550164,2172688912,1419114368,2694515432,288228056,1799813644,3319988168,3347456212,4225501308,2088601384,2402270176,3801843136,1189449980,2931870812,3754520196,3472218960,627908060,3054487628,2036858440,3019147680,908335892,1378877324,71570708,1242402668,1131180964,771191108,1349098532,3340088668,3139509860,4245769760,3439021112,2938872664,3948763660,3279581416,4294775792,4241184120,865831140,3502871672,2344336808,907059544,2824620440,929931808,924336104,1180821732,1090355460,3968948672,3282651108,4225098836,2521914952,2005443368,281762800,543270708,3431625564,1373077680,2332907268,518273984,2772283984,1688134016,1565583408,2013346352,3549959296,3347050512,3325119808,2529913220,3503218232,1264918768,1706933236,729827220,2000678152,1341862636,361562804,2177451088,3788210812,2272540052,7414276,4165343160,849380392,1084389804,2423263516,2069092104,678039996,1470798236,161619764,626031816,2123781352,2308733020,3842970440,1692294952,4269690808,4099194092,2029018800,1896338136,789282128,2373651520,1209246772,2372099048,1913540276,3092471152,1509320908,2716976760,237635176,4260416064,1084444592,3760855880,3032449380,169444772,1546752352,2563510584,486095684,1937957752,1794284492,1964209972,2670612784,2409774468,1460721604,3472570760,2898919472,3018085148,1798735796,472652560,3690840636,862806072,2779104064,1876649460,3663855196,477681724,362419584,713841492,1356469720,1085875216,1674062728,427225908,461469672,2655749564,1194277020,278976312,117190524,560898380,3821479456,1251117732,1204471624,3734702944,1100290084,4155882216,325264048,680061912,1990597944,2287747140,3844320204,2559992356,1102710516,1840091836,3994306848,826198300,3219015312,1665940936,1369540124,2846409724,3727291284,2535757056,3332094684,125885620,757927732,3416057840,4132840204,260798400,2367002016,3918071552,429876240,1857271600,4155446068,2698456292,177547408,3799135660,273877560,730577464,1907741016,3106221912,867829340,551054456,1967892156,1685097388,4157732936,2324506772,576600020,3353068600,2107473768,290285920,697452384,714422856,1868953568,204560096,4105196068,2516711784,1081775908,1416263092,2343083300,3423801764,3658112596,2730316968,694913668,886680960,4177134544,4023470676,4133444372,3326818232,3436608276,2484626520,2576912604,171465720,3642241664,2200492836,2268132448,278756116,1955891624,4083196316,610987976,1494363896,3087472592,2951080192,4283386456,4568924,3267049088,103500624,1801202192,2434730108,3485582416,3171184792,2791369252,3042452604,4114240488,1126118020,2425944804,2464003632,2144838416,56460188,2655276476,2082576892,3806254692,3406543128,4055128648,2258485336,2514550120,3060584696,3371018784,2219547936,1603527072,3452016516,491842568,1298073656,3604022760,916196332,1470383068,2334150456,3713241044,1108193424,3111637892,388580560,1962795108,844915868,4140674972,1082560980,628849848,4160824424,3717266472,1014708124,3703100328,3450736096,1749811456,3103146928,2236662716,1002470748,3711913088,3174165396,420402488,578110592,2638545996,1652478596,143685620,971829604,1465564152,1808653128,3973189484,3755084312,1807024500,537549860,2139577136,1954121004,3071587700,2092986380,4220047828,2218505744,3413296312,2883172776,567503536,4277194204,3696810612,75795908,3623837456,2897856932,2590245148,2070943336,3351252868,3886147724,3493497152,209056368,789162440,3358014652,1625423360,2711785740,4277652980,3664944308,3146303832,600820472,3820847548,1924983824,831046332,3703156196,1316899716,4158951644,3460055544,1285474128,2222535100,3650133552,3552214960,4025165076,1385770644,3096785268,4278030572,3788738460,237459352,2175898316,3711759444,844003888,3526671316,1479925108,2647708844,3201749060,3997824640,1385161028,1869637264,4263470952,2769184232,2640391508,1658105048,2315827260,2061653152,1507227240,4128651884,3078840296,2679453948,2319982048,3439508760,2226689792,139845932,1056052120,1766157452,2304529844,422120924,846849024,2456540912,2909198036,4263198824,1082076068,1491644660,3724458972,669046752,1831936148,3429955276,2856521060,446799120,2645363360,2891985392,3722650096,1442375508,2313932512,1686670956,494554056,3850014096,2614478856,2740878972,2673609228,12761612,3598385652,1984342268,943035216,631775528,2398843608,3804572680,888819200,1043382404,1894069148,1858933232,781322988,3144726852,1971886844,2567926796,3791783896,2332552292,4066948448,1126842112,2065636384,1956996956,1274272928,3540436548,106785792,1092822828,1777308932,624942972,2850497028,3561560084,3432269628,666902132,1500516596,393152856,2408432180,3154804728,1591861468,4237266968,711111996,1756332056,1231457208,3497519128,1577389380,560818944,1859233136,2010477364,1377390684,4188045104,1453452028,211516300,3743359172,1446374940,25568492,70017372,357876128,1377882672,3305940140,3398598064,2857212668,3078788364,2010568336,4018023872,1001382192,72098004,2416708324,2211266036,1693240856,656795664,1428247420,4174869632,363306400,744010168,888324184,4122139908,849893292,82720792,3427994536,3696459368,1686593164,1879411996,473970056,731171380,2574132200,671175536,496424956,734693456,1314616120,2463561328,920540364,2500442000,3392462724,1139352824,2466570796,2429314216,2742381836,833644604,2656614476,1718366420,4047393652,1680085536,1920488476,774474944,32068556,2206024140,3789952144,1309445988,3446449664,2567166628,1643676840,3810334616,2798908104,24057284,2673728420,2017612448,2912665712,2975088200,904910612,59557064,2033272952,3892551364,2183811100,3063981668,4067844512,3565260768,1305593016,3622035612,3940855816,1272537408,1299887944,2101483436,846806728,440859536,2935883264,1648819464,893698484,1141484964,3968710164,3650515240,1884670740,394047004,3347905440,2850942128,157447168,1979264220,3061645108,1919560724,1791834088,858839352,455765852,380441972,802952528,986776260,3763987380,2173105032,3069859388,3942071476,1420337356,3110228720,3571926148,4233485648,2374540620,279332992,3063788156,2856401444,1863708856,991292332,1927667824,757119964,1732848920,3355101608,1340991060,2500520868,1806422136,752930296,77205764,4260142232,2569678576,1325763692,3518238988,2318665920,856020616,2349401108,747579912,2101557908,1007953888,2081035888,2035817644,3792672320,3185045376,2055841636,822521128,2082348200,2593104976,2162153424,2060169976,477225584,93024836,2647249844,3657755596,2238381016,2485084448,2979802672,1526048,1787224840,3574089980,4153460972,2711458076,774381732,944031628,2665362352,1780787688,2309469112,167267524,1830976464,1735623300,1174823692,279224272,2825146716,2232082192,761973368,2246729020,1349433688,3174381072,1251215480,4056856460,3371964432,1769687872,4145819304,288436416,2240854972,2300471836,1552755644,3883442940,818571600,4075667984,3576650324,617565504,3039787436,402024172,769586568,3059874604,1085125920,3907652804,124385024,3858467212,2079003796,1919614944,3079449920,2723479204,2048823208,101905896,2724776840,314882820,3429838356,1493425040,2726636828,68446252,1166173488,83756556,2882298408,260959516,2344273796,3813761692,3067173520,1938130532,3693481940,2967553408,3718525540,3210066828,4068311280,1024873836,3326241368,1407422508,3510599432,2826475344,2908642824,4044275796,3993615956,1997951828,4004620796,894823656,2987929660,585089472,1383756172,1545586468,558672904,1954580172,1145133484,3919348076,1545173180,3257182052,3257607732,1630969856,2541458396,2066340700,1465904756,173567256,3447193168,1883582480,1218035328,343849332,3379120520,1249258452,4280149908,821245316,2415196612,1765312988,3404968388,2146906116,1806136496,2696309036,1088999580,3048352424,1887992744,3272808152,2195348412,1678235328,4070932940,2422372640,3767166892,2530882984,3862719968,100312956,455811716,862129660,3611725664,3481455176,2528708588,3307009884,3718640700,535632512,840426512,3892032752,3210763400,3859978644,3004256728,2812018808,291170668,1932490840,713703388,3703562564,461499988,3650685512,1987025336,1644322824,3347423676,1833126544,2840121096,1237863116,305342980,2592638496,3489661408,489937436,2430550028,1675788136,949227372,651626872,4113937408,3151645252,1934287128,2751761460,353225516,1573546144,955824736,274485416,750861304,2771863704,1588848200,1968284660,508820788,2138960932,359145724,4179371568,3354000792,1422774576,159493552,170849408,112087504,1163776052,3267286744,786635200,3485204556,3800708412,1045484036,2236101044,3700835624,7254152,2157179976,2584210416,948986392,4280313576,75064564,2036089880,2771223088,2920270896,3547018880,2526149564,1298033404,4028449196,3884871148,1452195804,2895284484,4125110000,2877755828,3688941824,1526872868,3125489328,2404433212,2781181108,1062423464,1134092576,4273963196,1728972912,4044941724,988489588,1756747140,3977440272,2039026360,1146054056,3186713880,117150912,2752575512,1617545732,1987019652,3537758900,3180113608,3784084180,3355172660,1865793712,4288035504,3452080580,2426533184,3925319120,418105304,1826691288,668850332,3487339320,3347466184,673237496,3864665480,3719935516,238280864,3308225648,724853916,2996347800,2778633420,532307616,2840078112,1767780876,2428297576,2233893992,1659427144,883744896,3383531900,601841540,3701722920,1343196888,822716208,3325642024,1643764404,2127804388,3931729472,2551187884,1251326364,903082528,176698320,921157740,3983013416,2072376648,2444992048,716163888,2252475896,559777044,876693852,1120231760,1745925376,4012008192,2794179928,3621392932,442306064,2654183680,827585312,3017495008,1595015304,1532921016,3187744684,3759270172,2277642336,154861436,2723131700,2448477244,3863171340,1954123696,106821064,977487552,2829163664,163236804,2312257592,703310612,2707271792,3105261424,3404461332,3666972780,1356672240,2603442688,1184251004,3310394308,2719193224,2948287868,1594092688,2086050196,3260363260,3587489716,2256652340,1519539312,1300150196,2905426772,2009511648,1882781532,306375804,1813072200,3883917752,1088018080,2598196464,914476408,1778568832,4041308872,1164696472,4247400828,193884972,667212004,1483098896,1780147888,395349544,1463911584,4010063980,2894977976,3689565728,1683970168,936989460,3888619056,3440233072,1834060272,4157326004,1336568724,456130936,26970912,3883150264,3138461100,2041072396,3779242228,2910590928,1806619660,3617434788,2415251032,2756250404,3925634880,551829200,1813352252,4194770484,2427686628,372011688,2896042824,1385819860,2592704996,2573390232,3238771644,598384020,670654988,331278576,944103688,4128617940,1169342776,608300088,1509076324,1059376696,2006613896,2376057560,2372299724,1545118864,277999188,1004185600,3129633932,2112279412,3259130080,2775220856,3813651684,4293165984,1245799376,875894824,710856076,1280755924,2781286844,2764885756,3988851728,587643940,1681830224,2499933556,1111234724,467919848,1463406492,766603048,1824809652,991710220,2195898540,4052364672,2287411308,3168925332,3606575148,319662816,3439961384,2359139604,2203511836,4126730380,197509092,2638643128,1645369492,568787016,2417017400,3821806248,2118547004,2172769008,1341315984,4098982880,4238115416,2020304360,250016604,1376546008,3732650412,1484358488,149801888,2427439560,1493220752,1323496080,1100526928,742677340,3904057400,3289733916,2795179612,1348910488,3574986396,1985944228,3369391392,1784192828,1907092560,3600093268,2224048916,1575742276,2725597200,783965452,3090143264,2421054040,4050838776,4249960080,3940879792,725286616,512823352,2880999964,4110257112,4288806424,3199324044,3833922336,1563793648,1055973848,1627031244,2794807280,225582916,481418580,711563200,2607299484,1644577412,3020336376,2298680512,3873735116,3440514784,2270418744,2981838060,3454724992,1745828188,2595068724,161692368,595226412,4251248864,17742272,3631580208,1454165956,449180164,4138631660,866605808,207315272,2673694488,82246268,947689392,3828682988,2296389164,2571747736,3903630176,566977860,2944908188,2435499616,1092659100,3196198012,2910737348,1931869012,2594458588,1236538620,85611864,3903563288,3187027152,733903480,754667640,244544496,3801054792,2475474208,972323448,869320348,967195768,3122851652,2044793148,1163501656,761399992,959800996,117187704,1831804556,929828712,978381120,3014391924,3887589044,2324943996,3289433084,2505510504,1009679800,3311861364,3160674176,1297772712,184761372,1568194856,3344729400,2580489456,3570675980,1708798356,2937303064,1353369196,51091868,3399728276,2993214228,1276666044,3893242264,3907908480};
12 ll gcd(ll x,ll y){
13 if (!y)return x;
14 return gcd(y,x%y);
15 }
16 ui get_sum(int l,int r){
17 r++;
18 for(int i=0;i<=r-l;i++)vis[i]=Phi[i]=i+l; 19 for(int i=1;p[i]*p[i]<=r;i++) 20 for(int j=(l+p[i]-1)/p[i]*p[i];j<=r;j+=p[i]){ 21 Phi[j-l]=Phi[j-l]/p[i]*(p[i]-1); 22 while (vis[j-l]%p[i]==0)vis[j-l]/=p[i]; 23 } 24 for(int i=0;i<=r-l;i++) 25 if (vis[i]>1)Phi[i]=Phi[i]/vis[i]*(vis[i]-1);
26 ui ans=0;
27 for(int i=0;i>1);
34 if ((ll)mid*(mid+1)<=n)l=mid; 35 else r=mid-1; 36 } 37 return Sum[l/K]+get_sum(l/K*K+1,l); 38 } 39 int main(){ 40 phi[1]=1; 41 for(int i=2;i(R<<1))break; 63 for(int j=i+2;;j++){ 64 int g=j/gcd(s,j); 65 if (s>R/g)break;
66 Phi*=g;
67 for(int k=0;k<P[g].size();k++)
68 if (s%P[g][k])Phi=Phi/P[g][k]*(P[g][k]-1);
69 s*=g;
70 v.push_back(make_pair(s,(ui)Phi));
71 }
72 }
73 sort(v.begin(),v.end());
74 for(int i=v.size();i;i--)sum[i-1]=sum[i]+v[i-1].second;
75 scanf("%d",&t);
76 while (t--){
77 scanf("%lld%lld",&L,&R);
78 ans=sum[lower_bound(v.begin(),v.end(),make_pair(L,(ui)0))-v.begin()];
79 ans-=sum[lower_bound(v.begin(),v.end(),make_pair(R+1,(ui)0))-v.begin()];
80 printf("%u\n",ans+calc(R)-calc(L-1));
81 }
82 return 0;
83 }

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章