【JZOJ3362】【BZOJ3758】数数
description
神犇最近闲来无事,于是就思考哲学,研究数字之美。在神犇看来,如果一个数的各位能够被分成两个集合,而且这两个集合里的数的和相等,那么这个数就是优美的(具体原因就只有神犇才知道了)。现在神犇在思考另一个问题,在区间[A,B]中有多少个数是优美的?这个问题对于神犇来说很简单,相信对于你来说也不难。
analysis
-
暴力明显好打,注意剪枝即可
-
\(10^9\)太小了,容易想到分段打表
-
每隔\(10^6\)打一次表,剩下的暴力求就好
code
#pragma GCC optimize("O3")
#pragma G++ optimize("O3")
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define mod 1000000
#define ll long long
#define reg register ll
#define fo(i,a,b) for (reg i=a;i<=b;++i)
#define fd(i,a,b) for (reg i=a;i>=b;--i)
using namespace std;
int f[105];
bool bz[15];
ll a[15];
ll x,y,tot,ans,tmp;
bool flag;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while (ch<'0' || '9'<ch){if (ch=='-')f=-1;ch=getchar();}
while ('0'<=ch && ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
inline void dfs(ll x,ll y)
{
if (y>tot-y)return;
if (x>a[0])
{
if (y==tot-y)++ans,flag=1;
return;
}
bz[x]=0,dfs(x+1,y);
if (flag)return;
bz[x]=1,dfs(x+1,y+a[x]);
}
inline ll get(ll x)
{
if (x<=10)return 0;
tmp=x/mod,ans=(ll)f[tmp];
fo(i,tmp*mod+1,x)
{
ll tmp=i;a[0]=tot=0;memset(bz,0,sizeof(bz));
while (tmp)a[++a[0]]=tmp%10,tot+=tmp%10,tmp/=10;
if (tot&1)continue;
flag=0,dfs(1,0);
}
return ans;
}
inline void init()
{
f[1]=376413,f[2]=832547,f[3]=1288828,f[4]=1744956,f[5]=2196800,f[6]=2647716,f[7]=3090920,
f[8]=3526440,f[9]=3951372,f[10]=4366880,f[11]=4823015,f[12]=5304766,f[13]=5797144,f[14]=6290672,
f[15]=6782004,f[16]=7272530,f[17]=7758910,f[18]=8238396,f[19]=8710536,f[20]=9182258,f[21]=9638539,
f[22]=10130918,f[23]=10610575,f[24]=11103529,f[25]=11590745,f[26]=12080513,f[27]=12565094,f[28]=13045216,
f[29]=13523103,f[30]=13996047,f[31]=14452175,f[32]=14945703,f[33]=15438658,f[34]=15913605,f[35]=16403907,
f[36]=16892727,f[37]=17371943,f[38]=17858307,f[39]=18339125,f[40]=18810719,f[41]=19262563,f[42]=19753895,
f[43]=20241111,f[44]=20731414,f[45]=21199399,f[46]=21684697,f[47]=22170473,f[48]=22655525,f[49]=23128982,
f[50]=23601310,f[51]=24052226,f[52]=24542752,f[53]=25032520,f[54]=25521340,f[55]=26006639,f[56]=26480512,
f[57]=26967738,f[58]=27450344,f[59]=27929454,f[60]=28401296,f[61]=28844500,f[62]=29330880,f[63]=29815461,
f[64]=30294677,f[65]=30780453,f[66]=31267680,f[67]=31727883,f[68]=32207445,f[69]=32681531,f[70]=33151141,
f[71]=33586661,f[72]=34066147,f[73]=34546269,f[74]=35032633,f[75]=35517685,f[76]=36000291,f[77]=36479854,
f[78]=36928875,f[79]=37398605,f[80]=37865237,f[81]=38290169,f[82]=38762309,f[83]=39240196,f[84]=39721014,
f[85]=40194471,f[86]=40673581,f[87]=41147667,f[88]=41617398,f[89]=42050819,f[90]=42514127,f[91]=42929635,
f[92]=43401357,f[93]=43874301,f[94]=44345895,f[95]=44818223,f[96]=45290065,f[97]=45759675,f[98]=46226307,
f[99]=46689616,f[100]=47111407,f[101]=47567542,f[102]=48049293,f[103]=48541671,f[104]=49035199,f[105]=49526531,
f[106]=50017057,f[107]=50503437,f[108]=50982923,f[109]=51455063,f[110]=51926786,f[111]=52408537,f[112]=52900916,
f[113]=53398017,f[114]=53897101,f[115]=54395976,f[116]=54894264,f[117]=55390376,f[118]=55882154,f[119]=56370124,
f[120]=56858336,f[121]=57350715,f[122]=57847816,f[123]=58346901,f[124]=58846682,f[125]=59346650,f[126]=59846494,
f[127]=60345546,f[128]=60842736,f[129]=61337762,f[130]=61832643,f[131]=62326171,f[132]=62825256,f[133]=63325037,
f[134]=63822618,f[135]=64321881,f[136]=64821477,f[137]=65319367,f[138]=65818159,f[139]=66315614,f[140]=66811192,
f[141]=67302524,f[142]=67801399,f[143]=68301368,f[144]=68800631,f[145]=69295186,f[146]=69792675,f[147]=70292149,
f[148]=70790949,f[149]=71286703,f[150]=71781713,f[151]=72272239,f[152]=72770527,f[153]=73270371,f[154]=73769968,
f[155]=74267457,f[156]=74763402,f[157]=75261351,f[158]=75759527,f[159]=76256605,f[160]=76751555,f[161]=77237935,
f[162]=77734047,f[163]=78233099,f[164]=78730989,f[165]=79230464,f[166]=79728413,f[167]=80220834,f[168]=80714563,
f[169]=81209373,f[170]=81704149,f[171]=82183635,f[172]=82675413,f[173]=83172603,f[174]=83671395,f[175]=84170195,
f[176]=84668372,f[177]=85162101,f[178]=85646750,f[179]=86134011,f[180]=86626601,f[181]=87098741,f[182]=87586711,
f[183]=88081737,f[184]=88579192,f[185]=89074946,f[186]=89572024,f[187]=90066835,f[188]=90554096,f[189]=91029271,
f[190]=91513942,f[191]=91985664,f[192]=92473876,f[193]=92968757,f[194]=93464335,f[195]=93959345,f[196]=94454295,
f[197]=94949071,f[198]=95441662,f[199]=95926333,f[200]=96400455,f[201]=96856736,f[202]=97349115,f[203]=97828772,
f[204]=98321726,f[205]=98808942,f[206]=99298710,f[207]=99783291,f[208]=100263413,f[209]=100741300,f[210]=101214244,
f[211]=101706623,f[212]=102203724,f[213]=102702809,f[214]=103202590,f[215]=103702558,f[216]=104202402,f[217]=104701454,
f[218]=105198644,f[219]=105693670,f[220]=106188552,f[221]=106668209,f[222]=107167293,f[223]=107654509,f[224]=108153408,
f[225]=108643571,f[226]=109140447,f[227]=109631936,f[228]=110124934,f[229]=110615086,f[230]=111104170,f[231]=111597125,
f[232]=112096906,f[233]=112595804,f[234]=113093027,f[235]=113592810,f[236]=114091415,f[237]=114589181,f[238]=115087418,
f[239]=115585176,f[240]=116080738,f[241]=116567954,f[242]=117067923,f[243]=117558086,f[244]=118057868,f[245]=118549357,
f[246]=119048442,f[247]=119540443,f[248]=120037757,f[249]=120529913,f[250]=121025141,f[251]=121514909,f[252]=122014753,
f[253]=122511630,f[254]=123010235,f[255]=123509319,f[256]=124005151,f[257]=124504320,f[258]=124999107,f[259]=125496723,
f[260]=125991518,f[261]=126476099,f[262]=126975151,f[263]=127466640,f[264]=127964407,f[265]=128456408,f[266]=128955576,
f[267]=129444361,f[268]=129941988,f[269]=130432181,f[270]=130927549,f[271]=131407671,f[272]=131904861,f[273]=132397859,
f[274]=132896096,f[275]=133393411,f[276]=133888198,f[277]=134385824,f[278]=134870790,f[279]=135365761,f[280]=135853348,
f[281]=136331235,f[282]=136826261,f[283]=137316413,f[284]=137814171,f[285]=138306327,f[286]=138803944,f[287]=139294137,
f[288]=139789107,f[289]=140268613,f[290]=140761869,f[291]=141234813,f[292]=141729694,f[293]=142218778,f[294]=142714340,
f[295]=143209568,f[296]=143704363,f[297]=144199732,f[298]=144687319,f[299]=145180575,f[300]=145654892,f[301]=146111020,
f[302]=146604548,f[303]=147097503,f[304]=147572450,f[305]=148062752,f[306]=148551572,f[307]=149030788,f[308]=149517152,
f[309]=149997970,f[310]=150469564,f[311]=150963092,f[312]=151462177,f[313]=151961958,f[314]=152459539,f[315]=152958802,
f[316]=153458398,f[317]=153956288,f[318]=154455080,f[319]=154952535,f[320]=155448113,f[321]=155941068,f[322]=156440849,
f[323]=156939747,f[324]=157436970,f[325]=157936753,f[326]=158435358,f[327]=158933124,f[328]=159431361,f[329]=159929119,
f[330]=160424682,f[331]=160899629,f[332]=161397209,f[333]=161894432,f[334]=162373648,f[335]=162870479,f[336]=163366196,
f[337]=163847035,f[338]=164342307,f[339]=164834856,f[340]=165316242,f[341]=165806545,f[342]=166305808,f[343]=166805590,
f[344]=167302421,f[345]=167797533,f[346]=168296439,f[347]=168794206,f[348]=169291181,f[349]=169787227,f[350]=170282583,
f[351]=170771403,f[352]=171271000,f[353]=171769605,f[354]=172265321,f[355]=172764227,f[356]=173259685,f[357]=173756939,
f[358]=174255102,f[359]=174749455,f[360]=175244787,f[361]=175724003,f[362]=176221893,f[363]=176719660,f[364]=177200499,
f[365]=177698265,f[366]=178195519,f[367]=178676905,f[368]=179174053,f[369]=179669962,f[370]=180151503,f[371]=180637867,
f[372]=181136659,f[373]=181634896,f[374]=182130169,f[375]=182627144,f[376]=183125306,f[377]=183622454,f[378]=184112942,
f[379]=184610046,f[380]=185104838,f[381]=185585656,f[382]=186083111,f[383]=186580869,f[384]=187073418,f[385]=187569465,
f[386]=188063818,f[387]=188559726,f[388]=189056830,f[389]=189540680,f[390]=190034891,f[391]=190506485,f[392]=191002063,
f[393]=191497625,f[394]=191979011,f[395]=192474367,f[396]=192969700,f[397]=193451241,f[398]=193946033,f[399]=194440244,
f[400]=194913068,f[401]=195364912,f[402]=195856244,f[403]=196343460,f[404]=196833763,f[405]=197301748,f[406]=197787046,
f[407]=198272822,f[408]=198757874,f[409]=199231331,f[410]=199703659,f[411]=200194991,f[412]=200693866,f[413]=201193835,
f[414]=201693098,f[415]=202187653,f[416]=202685142,f[417]=203184616,f[418]=203683416,f[419]=204179170,f[420]=204674180,
f[421]=205161396,f[422]=205661365,f[423]=206151528,f[424]=206651310,f[425]=207142799,f[426]=207641884,f[427]=208133885,
f[428]=208631199,f[429]=209123355,f[430]=209618583,f[431]=210108886,f[432]=210608149,f[433]=211107931,f[434]=211604762,
f[435]=212099874,f[436]=212598780,f[437]=213096547,f[438]=213593522,f[439]=214089568,f[440]=214584925,f[441]=215052910,
f[442]=215547464,f[443]=216038953,f[444]=216534065,f[445]=217007522,f[446]=217499718,f[447]=217990901,f[448]=218484410,
f[449]=218959905,f[450]=219446727,f[451]=219932026,f[452]=220429515,f[453]=220928599,f[454]=221427505,f[455]=221919701,
f[456]=222413231,f[457]=222911993,f[458]=223409872,f[459]=223904583,f[460]=224393574,f[461]=224879350,f[462]=225378825,
f[463]=225870826,f[464]=226368592,f[465]=226859775,f[466]=227358537,f[467]=227847477,f[468]=228346119,f[469]=228838089,
f[470]=229333643,f[471]=229818695,f[472]=230317495,f[473]=230814810,f[474]=231311785,f[475]=231805293,f[476]=232303172,
f[477]=232801814,f[478]=233291625,f[479]=233787283,f[480]=234281777,f[481]=234755234,f[482]=235250988,f[483]=235743144,
f[484]=236239191,f[485]=236714686,f[486]=237209396,f[487]=237701366,f[488]=238197024,f[489]=238673284,f[490]=239165608,
f[491]=239637936,f[492]=240132946,f[493]=240628174,f[494]=241123530,f[495]=241610353,f[496]=242099344,f[497]=242594898,
f[498]=243089392,f[499]=243581716,f[500]=244056062,f[501]=244506978,f[502]=244997504,f[503]=245487272,f[504]=245976092,
f[505]=246461391,f[506]=246935264,f[507]=247422490,f[508]=247905096,f[509]=248384206,f[510]=248856048,f[511]=249346574,
f[512]=249844862,f[513]=250344706,f[514]=250844303,f[515]=251341792,f[516]=251837737,f[517]=252335686,f[518]=252833862,
f[519]=253330940,f[520]=253825890,f[521]=254315658,f[522]=254815502,f[523]=255312379,f[524]=255810984,f[525]=256310068,
f[526]=256805900,f[527]=257305069,f[528]=257799856,f[529]=258297472,f[530]=258792267,f[531]=259281087,f[532]=259780684,
f[533]=260279289,f[534]=260775005,f[535]=261273911,f[536]=261769369,f[537]=262266623,f[538]=262764786,f[539]=263259139,
f[540]=263754471,f[541]=264239770,f[542]=264737259,f[543]=265236343,f[544]=265735249,f[545]=266227445,f[546]=266720975,
f[547]=267219737,f[548]=267717616,f[549]=268212327,f[550]=268701319,f[551]=269175192,f[552]=269671136,f[553]=270166968,
f[554]=270662426,f[555]=271155956,f[556]=271637394,f[557]=272132980,f[558]=272626656,f[559]=273118401,f[560]=273606213,
f[561]=274093440,f[562]=274591389,f[563]=275090557,f[564]=275587811,f[565]=276086573,f[566]=276582159,f[567]=277074753,
f[568]=277572087,f[569]=278069041,f[570]=278564272,f[571]=279046878,f[572]=279545055,f[573]=280039842,f[574]=280538004,
f[575]=281035883,f[576]=281529559,f[577]=282026893,f[578]=282513143,f[579]=283009664,f[580]=283502662,f[581]=283981772,
f[582]=284478850,f[583]=284976467,f[584]=285470820,f[585]=285965530,f[586]=286457275,f[587]=286954229,f[588]=287450750,
f[589]=287934208,f[590]=288427696,f[591]=288899538,f[592]=289394488,f[593]=289889283,f[594]=290384616,f[595]=290873607,
f[596]=291361419,f[597]=291856650,f[598]=292349648,f[599]=292843136,f[600]=293317366,f[601]=293760570,f[602]=294246950,
f[603]=294731531,f[604]=295210747,f[605]=295696523,f[606]=296183750,f[607]=296643953,f[608]=297123515,f[609]=297597601,
f[610]=298067211,f[611]=298553591,f[612]=299049703,f[613]=299548755,f[614]=300046645,f[615]=300546120,f[616]=301044069,
f[617]=301536490,f[618]=302030219,f[619]=302525029,f[620]=303019805,f[621]=303504386,f[622]=304003438,f[623]=304494927,
f[624]=304992694,f[625]=305484695,f[626]=305983863,f[627]=306472648,f[628]=306970275,f[629]=307460468,f[630]=307955836,
f[631]=308435052,f[632]=308932942,f[633]=309430709,f[634]=309911548,f[635]=310409314,f[636]=310906568,f[637]=311387954,
f[638]=311885102,f[639]=312381011,f[640]=312862552,f[641]=313348328,f[642]=313847803,f[643]=314339804,f[644]=314837570,
f[645]=315328753,f[646]=315827515,f[647]=316316455,f[648]=316815097,f[649]=317307067,f[650]=317802621,f[651]=318289848,
f[652]=318787797,f[653]=319286965,f[654]=319784219,f[655]=320282981,f[656]=320778567,f[657]=321271161,f[658]=321768495,
f[659]=322265449,f[660]=322760681,f[661]=323220884,f[662]=323713304,f[663]=324202089,f[664]=324683475,f[665]=325172415,
f[666]=325665009,f[667]=326128508,f[668]=326618472,f[669]=327104745,f[670]=327585453,f[671]=328065016,f[672]=328558745,
f[673]=329056371,f[674]=329553519,f[675]=330052161,f[676]=330549495,f[677]=331039459,f[678]=331524705,f[679]=332017239,
f[680]=332510934,f[681]=332985020,f[682]=333479831,f[683]=333970024,f[684]=334465932,f[685]=334957902,f[686]=335454856,
f[687]=335941129,f[688]=336433663,f[689]=336912903,f[690]=337405293,f[691]=337874903,f[692]=338369679,f[693]=338865048,
f[694]=339346589,f[695]=339842143,f[696]=340337374,f[697]=340818082,f[698]=341311777,f[699]=341804167,f[700]=342276694,
f[701]=342712214,f[702]=343191700,f[703]=343671822,f[704]=344158186,f[705]=344643238,f[706]=345125844,f[707]=345605407,
f[708]=346054428,f[709]=346524158,f[710]=346990790,f[711]=347470276,f[712]=347962054,f[713]=348459244,f[714]=348958036,
f[715]=349456836,f[716]=349955013,f[717]=350448742,f[718]=350933391,f[719]=351420652,f[720]=351913242,f[721]=352393364,
f[722]=352890554,f[723]=353383552,f[724]=353881789,f[725]=354379104,f[726]=354873891,f[727]=355371517,f[728]=355856483,
f[729]=356351454,f[730]=356839041,f[731]=357325405,f[732]=357824197,f[733]=358322434,f[734]=358817707,f[735]=359314682,
f[736]=359812844,f[737]=360309992,f[738]=360800480,f[739]=361297584,f[740]=361792376,f[741]=362277428,f[742]=362776228,
f[743]=363273543,f[744]=363770518,f[745]=364264026,f[746]=364761905,f[747]=365260547,f[748]=365750358,f[749]=366246016,
f[750]=366740510,f[751]=367223116,f[752]=367721293,f[753]=368216080,f[754]=368714242,f[755]=369212121,f[756]=369705797,
f[757]=370203131,f[758]=370689381,f[759]=371185902,f[760]=371678900,f[761]=372158463,f[762]=372652192,f[763]=373149818,
f[764]=373646966,f[765]=374145608,f[766]=374642942,f[767]=375132906,f[768]=375618152,f[769]=376110686,f[770]=376604382,
f[771]=377053403,f[772]=377538051,f[773]=378023017,f[774]=378513505,f[775]=379003316,f[776]=379489566,f[777]=379974812,
f[778]=380427196,f[779]=380908305,f[780]=381388631,f[781]=381858362,f[782]=382345623,f[783]=382840593,f[784]=383337697,
f[785]=383833355,f[786]=384329876,f[787]=384822410,f[788]=385303519,f[789]=385778157,f[790]=386266143,f[791]=386732775,
f[792]=387225366,f[793]=387712953,f[794]=388207745,f[795]=388702239,f[796]=389195237,f[797]=389688932,f[798]=390169258,
f[799]=390657244,f[800]=391130374,f[801]=391555306,f[802]=392027446,f[803]=392505333,f[804]=392986151,f[805]=393459608,
f[806]=393938718,f[807]=394412804,f[808]=394882535,f[809]=395315956,f[810]=395779264,f[811]=396251404,f[812]=396739374,
f[813]=397234400,f[814]=397731855,f[815]=398227609,f[816]=398724687,f[817]=399219498,f[818]=399706759,f[819]=400181934,
f[820]=400666605,f[821]=401144492,f[822]=401639518,f[823]=402129670,f[824]=402627428,f[825]=403119584,f[826]=403617201,
f[827]=404107394,f[828]=404602364,f[829]=405081870,f[830]=405575126,f[831]=406055944,f[832]=406553399,f[833]=407051157,
f[834]=407543706,f[835]=408039753,f[836]=408534106,f[837]=409030014,f[838]=409527118,f[839]=410010968,f[840]=410505179,
f[841]=410978636,f[842]=411474390,f[843]=411966546,f[844]=412462593,f[845]=412938088,f[846]=413432798,f[847]=413924768,
f[848]=414420426,f[849]=414896686,f[850]=415389010,f[851]=415868120,f[852]=416365198,f[853]=416862815,f[854]=417357168,
f[855]=417851878,f[856]=418343623,f[857]=418840577,f[858]=419337098,f[859]=419820556,f[860]=420314044,f[861]=420788130,
f[862]=421282941,f[863]=421773134,f[864]=422269042,f[865]=422761012,f[866]=423257966,f[867]=423744239,f[868]=424236773,
f[869]=424716013,f[870]=425208403,f[871]=425678134,f[872]=426165395,f[873]=426660365,f[874]=427157469,f[875]=427653127,
f[876]=428149648,f[877]=428642182,f[878]=429123291,f[879]=429597929,f[880]=430085916,f[881]=430519337,f[882]=430994511,
f[883]=431474017,f[884]=431957867,f[885]=432434127,f[886]=432917585,f[887]=433396825,f[888]=433871463,f[889]=434306086,
f[890]=434779290,f[891]=435242599,f[892]=435727270,f[893]=436220526,f[894]=436714737,f[895]=437207061,f[896]=437700549,
f[897]=438192939,f[898]=438680925,f[899]=439154129,f[900]=439626259,f[901]=440041767,f[902]=440513489,f[903]=440986433,
f[904]=441458027,f[905]=441930355,f[906]=442402197,f[907]=442871807,f[908]=443338439,f[909]=443801748,f[910]=444223539,
f[911]=444695261,f[912]=445183473,f[913]=445678354,f[914]=446173932,f[915]=446668942,f[916]=447163892,f[917]=447658668,
f[918]=448151259,f[919]=448635930,f[920]=449110052,f[921]=449582996,f[922]=450077877,f[923]=450566961,f[924]=451062523,
f[925]=451557751,f[926]=452052546,f[927]=452547915,f[928]=453035502,f[929]=453528758,f[930]=454003075,f[931]=454474669,
f[932]=454970247,f[933]=455465809,f[934]=455947195,f[935]=456442551,f[936]=456937884,f[937]=457419425,f[938]=457914217,
f[939]=458408428,f[940]=458881252,f[941]=459353580,f[942]=459848590,f[943]=460343818,f[944]=460839174,f[945]=461325997,
f[946]=461814988,f[947]=462310542,f[948]=462805036,f[949]=463297360,f[950]=463771706,f[951]=464243548,f[952]=464738498,
f[953]=465233293,f[954]=465728626,f[955]=466217617,f[956]=466705429,f[957]=467200660,f[958]=467693658,f[959]=468187146,
f[960]=468661376,f[961]=469130986,f[962]=469625762,f[963]=470121131,f[964]=470602672,f[965]=471098226,f[966]=471593457,
f[967]=472074165,f[968]=472567860,f[969]=473060250,f[970]=473532777,f[971]=473999409,f[972]=474492000,f[973]=474979587,
f[974]=475474379,f[975]=475968873,f[976]=476461871,f[977]=476955566,f[978]=477435892,f[979]=477923878,f[980]=478397008,
f[981]=478860317,f[982]=479344988,f[983]=479838244,f[984]=480332455,f[985]=480824779,f[986]=481318267,f[987]=481810657,
f[988]=482298643,f[989]=482771847,f[990]=483243978,f[991]=483665769,f[992]=484139891,f[993]=484614208,f[994]=485087032,
f[995]=485561378,f[996]=486035608,f[997]=486508135,f[998]=486981265,f[999]=487453395,f[1000]=487875963;
}
int main()
{
//freopen("T2.in","r",stdin);
init(),x=read(),y=read();
printf("%lld\n",get(y)-get(x-1));
return 0;
}