图片源于”洛谷“;
废话不多说直接上代码:
#include"iostream"
using namespace std;
long long sum=0;
int a[501]={0,1,2,2,4,4,6,6,10,10,14,14,20,20,26,26,36,36,46,46,60,60,74,74,94,94,114,114,140,140,166,166,202,202,238,238,284,284,330,330,390,390,450,450,524,524,598,598,692,692,786,786,900,900,1014,1014,1154,1154,1294,1294,1460,1460,1626,1626,1828,1828,2030,2030,2268,2268,2506,2506,2790,2790,3074,3074,3404,3404,3734,3734,4124,4124,4514,4514,4964,4964,5414,5414,5938,5938,6462,6462,7060,7060,7658,7658,8350,8350,9042,9042,9828,9828,10614,10614,11514,11514,12414,12414,13428,13428,14442,14442,15596,15596,16750,16750,18044,18044,19338,19338,20798,20798,22258,22258,23884,23884,25510,25510,27338,27338,29166,29166,31196,31196,33226,33226,35494,35494,37762,37762,40268,40268,42774,42774,45564,45564,48354,48354,51428,51428,54502,54502,57906,57906,61310,61310,65044,65044,68778,68778,72902,72902,77026,77026,81540,81540,86054,86054,91018,91018,95982,95982,101396,101396,106810,106810,112748,112748,118686,118686,125148,125148,131610,131610,138670,138670,145730,145730,153388,153388,161046,161046,169396,169396,177746,177746,186788,186788,195830,195830,205658,205658,215486,215486,226100,226100,236714,236714,248228,248228,259742,259742,272156,272156,284570,284570,297998,297998,311426,311426,325868,325868,340310,340310,355906,355906,371502,371502,388252,388252,405002,405002,423046,423046,441090,441090,460428,460428,479766,479766,500564,500564,521362,521362,543620,543620,565878,565878,589762,589762,613646,613646,639156,639156,664666,664666,692004,692004,719342,719342,748508,748508,777674,777674,808870,808870,840066,840066,873292,873292,906518,906518,942012,942012,977506,977506,1015268,1015268,1053030,1053030,1093298,1093298,1133566,1133566,1176340,1176340,1219114,1219114,1264678,1264678,1310242,1310242,1358596,1358596,1406950,1406950,1458378,1458378,1509806,1509806,1564308,1564308,1618810,1618810,1676716,1676716,1734622,1734622,1795932,1795932,1857242,1857242,1922286,1922286,1987330,1987330,2056108,2056108,2124886,2124886,2197788,2197788,2270690,2270690,2347716,2347716,2424742,2424742,2506282,2506282,2587822,2587822,2673876,2673876,2759930,2759930,2850948,2850948,2941966,2941966,3037948,3037948,3133930,3133930,3235326,3235326,3336722,3336722,3443532,3443532,3550342,3550342,3663090,3663090,3775838,3775838,3894524,3894524,4013210,4013210,4138358,4138358,4263506,4263506,4395116,4395116,4526726,4526726,4665396,4665396,4804066,4804066,4949796,4949796,5095526,5095526,5248914,5248914,5402302,5402302,5563348,5563348,5724394,5724394,5893790,5893790,6063186,6063186,6240932,6240932,6418678,6418678,6605466,6605466,6792254,6792254,6988084,6988084,7183914,7183914,7389572,7389572,7595230,7595230,7810716,7810716,8026202,8026202,8252302,8252302,8478402,8478402,8715116,8715116,8951830,8951830,9200058,9200058,9448286,9448286,9708028,9708028,9967770,9967770,10239926,10239926,10512082,10512082,10796652,10796652,11081222,11081222,11379220,11379220,11677218,11677218,11988644,11988644,12300070,12300070,12625938,12625938,12951806,12951806,13292116,13292116,13632426,13632426,13988332,13988332,14344238,14344238,14715740,14715740,15087242,15087242,15475494,15475494,15863746,15863746,16268748,16268748,16673750,16673750,17096796,17096796,17519842,17519842,17960932,17960932,18402022,18402022,18862450,18862450,19322878,19322878,19802644,19802644,20282410,20282410,20782974,20782974,21283538,21283538,21804900,21804900,22326262,22326262,22869882,22869882,23413502,23413502,23979380,23979380,24545258,24545258,25135020,25135020,25724782,25724782,26338428
};
void lf(int n)
{
if(n==0) return ;
if(n<=500)
sum=sum+a[n]-1;
else
for(int i=1;i<=n/2;i++){
sum++;
lf(i);
}
}
int main()
{
int n;
cin>>n;
lf(n);
cout<<sum+1;
return 0;
}
第一眼,看到这道题,就是递归,但是很明显,递归会超时.所以直接打表格,就欧克了。