Editorial for Đếm số giai thừa 2!


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

const a:array[0..1000] of real=(0.0,5565708.9172,11733474.5771,18128483.9561,24671065.7378,31323381.3607,38063144.3990,44875628.7284,51750367.8913,58679536.1240,65657059.0801,72678084.1556,79738645.1084,86835439.2713,93965673.7250,101126955.6444,108317212.0132,115534629.4854,122777608.4443,130044727.3004,137334714.3248,144646425.1296,151978824.4465,159330971.2246,166702006.3246,174091142.2673,181497654.6243,188920874.7357,196360183.5069,203815006.0942,211284807.3222,218769087.7146,226267380.0370,233779246.2715,241304274.9596,248842078.8568,256392292.8564,263954572.1433,271528590.5481,279114039.0744,286710624.5771,294318068.5730,301936106.1675,309564485.0839,317202964.7825,324851315.6599,332509318.3203,340176762.9086,347853448.5024,355539182.5523,363233780.3702,370937064.6568,378648865.0671,386369017.8092,394097365.2730,401833755.6868,409578042.7990,417330085.5819,425089747.9571,432856898.5391,440631410.3970,448413160.8313,456202031.1662,463997906.5544,471800675.7954,479610231.1636,487426468.2490,495249285.8056,503078585.6100,510914272.3281,518756253.3895,526604438.8687,534458741.3738,542319075.9407,550185359.9330,558057512.9483,565935456.7282,573819115.0741,581708413.7666,589603280.4895,597503644.7578,605409437.8484,613320592.7354,621237044.0279,629158727.9106,637085582.0878,645017545.7297,652954559.4211,660896565.1131,668843506.0759,676795326.8545,684751973.2267,692713392.1618,700679531.7819,708650341.3252,716625771.1097,724605772.4994,732590297.8718,740579300.5861,748572734.9537,756570556.2088,764572720.4811,772579184.7690,780589906.9142,788604845.5768,796623960.2123,804647211.0482,812674559.0625,820705965.9629,828741394.1660,836780806.7779,844824167.5759,852871440.9897,860922592.0843,868977586.5430,877036390.6514,885098971.2810,893165295.8749,901235332.4327,909309049.4962,917386416.1361,925467401.9386,933551976.9926,941640111.8772,949731777.6501,957826945.8358,965925588.4145,974027677.8109,982133186.8842,990242088.9176,998354357.6087,1006469967.0595,1014588891.7675,1022711106.6167,1030836586.8687,1038965308.1544,1047097246.4656,1055232378.1474,1063370679.8900,1071512128.7216,1079656702.0009,1087804377.4100,1095955132.9476,1104108946.9223,1112265797.9462,1120425664.9281,1128588527.0682,1136754363.8512,1144923155.0413,1153094880.6758,1161269521.0603,1169447056.7627,1177627468.6086,1185810737.6756,1193996845.2888,1202185773.0159,1210377502.6623,1218572016.2667,1226769296.0967,1234969324.6444,1243172084.6218,1251377558.9575,1259585730.7917,1267796583.4731,1276010100.5545,1284226265.7894,1292445063.1281,1300666476.7145,1308890490.8822,1317117090.1514,1325346259.2254,1333577982.9875,1341812246.4979,1350049034.9904,1358288333.8696,1366530128.7079,1374774405.2424,1383021149.3725,1391270347.1568,1399521984.8105,1407776048.7030,1416032525.3550,1424291401.4363,1432552663.7630,1440816299.2953,1449082295.1354,1457350638.5247,1465621316.8417,1473894317.6002,1482169628.4466,1490447237.1582,1498727131.6407,1507009299.9267,1515293730.1733,1523580410.6605,1531869329.7890,1540160476.0783,1548453838.1655,1556749404.8027,1565047164.8556,1573347107.3020,1581649221.2299,1589953495.8358,1598259920.4232,1606568484.4008,1614879177.2815,1623191988.6803,1631506908.3130,1639823925.9948,1648143031.6389,1656464215.2550,1664787466.9478,1673112776.9160,1681440135.4507,1689769532.9341,1698100959.8383,1706434406.7241,1714769864.2398,1723107323.1196,1731446774.1828,1739788208.3328,1748131616.5554,1756476989.9181,1764824319.5689,1773173596.7351,1781524812.7223,1789877958.9136,1798233026.7682,1806590007.8205,1814948893.6793,1823309676.0266,1831672346.6167,1840036897.2753,1848403319.8987,1856771606.4526,1865141748.9715,1873513739.5577,1881887570.3801,1890263233.6742,1898640721.7403,1907020026.9435,1915401141.7122,1923784058.5380,1932168769.9741,1940555268.6353,1948943547.1969,1957333598.3940,1965725415.0207,1974118989.9294,1982514316.0303,1990911386.2905,1999310193.7332,2007710731.4373,2016112992.5368,2024516970.2198,2032922657.7279,2041330048.3560,2049739135.4513,2058149912.4126,2066562372.6901,2074976509.7844,2083392317.2462,2091809788.6756,2100228917.7215,2108649698.0813,2117072123.4998,2125496187.7694,2133921884.7288,2142349208.2630,2150778152.3029,2159208710.8240,2167640877.8470,2176074647.4362,2184510013.6999,2192946970.7894,2201385512.8989,2209825634.2644,2218267329.1641,2226710591.9174,2235155416.8844,2243601798.4657,2252049731.1021,2260499209.2737,2268950227.4999,2277402780.3387,2285856862.3866,2294312468.2780,2302769592.6846,2311228230.3154,2319688375.9163,2328150024.2691,2336613170.1922,2345077808.5391,2353543934.1987,2362011542.0949,2370480627.1862,2378951184.4649,2387423208.9575,2395896695.7238,2404371639.8569,2412848036.4827,2421325880.7593,2429805167.8774,2438285893.0594,2446768051.5591,2455251638.6616,2463736649.6830,2472223079.9699,2480710924.8993,2489200179.8782,2497690840.3434,2506182901.7609,2514676359.6261,2523171209.4632,2531667446.8249,2540165067.2925,2548664066.4749,2557164440.0093,2565666183.5601,2574169292.8191,2582673763.5050,2591179591.3633,2599686772.1662,2608195301.7119,2616705175.8246,2625216390.3546,2633728941.1773,2642242824.1939,2650758035.3301,2659274570.5370,2667792425.7899,2676311597.0887,2684832080.4574,2693353871.9441,2701876967.6203,2710401363.5813,2718927055.9457,2727454040.8551,2735982314.4740,2744511872.9897,2753042712.6120,2761574829.5728,2770108220.1263,2778642880.5485,2787178807.1371,2795715996.2115,2804254444.1122,2812794147.2011,2821335101.8608,2829877304.4948,2838420751.5274,2846965439.4031,2855511364.5865,2864058523.5628,2872606912.8367,2881156528.9329,2889707368.3954,2898259427.7878,2906812703.6929,2915367192.7127,2923922891.4680,2932479796.5984,2941037904.7622,2949597212.6359,2958157716.9148,2966719414.3118,2975282301.5582,2983846375.4031,2992411632.6131,3000978069.9726,3009545684.2833,3018114472.3644,3026684431.0520,3035255557.1993,3043827847.6762,3052401299.3698,3060975909.1834,3069551674.0369,3078128590.8664,3086706656.6245,3095285868.2796,3103866222.8163,3112447717.2348,3121030348.5512,3129614113.7970,3138199010.0193,3146785034.2805,3155372183.6581,3163960455.2450,3172549846.1488,3181140353.4921,3189731974.4122,3198324706.0611,3206918545.6052,3215513490.2256,3224109537.1174,3232706683.4901,3241304926.5672,3249904263.5862,3258504691.7985,3267106208.4693,3275708810.8775,3284312496.3154,3292917262.0889,3301523105.5174,3310130023.9332,3318738014.6823,3327347075.1232,3335957202.6278,3344568394.5808,3353180648.3795,3361793961.4341,3370408331.1673,3379023755.0143,3387640230.4229,3396257754.8530,3404876325.7768,3413495940.6787,3422116597.0552,3430738292.4147,3439361024.2776,3447984790.1759,3456609587.6535,3465235414.2659,3473862267.5802,3482490145.1749,3491119044.6398,3499748963.5764,3508379899.5969,3517011850.3251,3525644813.3957,3534278786.4543,3542913767.1577,3551549753.1732,3560186742.1792,3568824731.8647,3577463719.9291,3586103704.0826,3594744682.0459,3603386651.5500,3612029610.3362,3620673556.1562,3629318486.7717,3637964399.9548,3646611293.4875,3655259165.1616,3663908012.7793,3672557834.1522,3681208627.1020,3689860389.4599,3698513119.0669,3707166813.7735,3715821471.4399,3724477089.9355,3733133667.1394,3741791200.9399,3750449689.2344,3759109129.9299,3767769520.9423,3776430860.1967,3785093145.6272,3793756375.1768,3802420546.7977,3811085658.4506,3819751708.1053,3828418693.7402,3837086613.3425,3845755464.9079,3854425246.4407,3863095955.9539,3871767591.4689,3880440151.0154,3889113632.6315,3897788034.3638,3906463354.2668,3915139590.4037,3923816740.8453,3932494803.6711,3941173776.9680,3949853658.8316,3958534447.3648,3967216140.6788,3975898736.8927,3984582234.1331,3993266630.5346,4001951924.2393,4010638113.3972,4019325196.1658,4028013170.7101,4036702035.2027,4045391787.8238,4054082426.7607,4062773950.2084,4071466356.3691,4080159643.4522,4088853809.6746,4097548853.2601,4106244772.4400,4114941565.4524,4123639230.5426,4132337765.9631,4141037169.9731,4149737440.8389,4158438576.8338,4167140576.2377,4175843437.3376,4184547158.4271,4193251737.8067,4201957173.7834,4210663464.6711,4219370608.7902,4228078604.4676,4236787450.0369,4245497143.8381,4254207684.2178,4262919069.5290,4271631298.1309,4280344368.3894,4289058278.6763,4297773027.3701,4306488612.8554,4315205033.5227,4323922287.7693,4332640373.9981,4341359290.6184,4350079036.0456,4358799608.7008,4367521007.0114,4376243229.4107,4384966274.3380,4393690140.2382,4402414825.5625,4411140328.7676,4419866648.3163,4428593782.6768,4437321730.3234,4446050489.7358,4454780059.3995,4463510437.8060,4472241623.4515,4480973614.8386,4489706410.4754,4498440008.8750,4507174408.5563,4515909608.0438,4524645605.8673,4533382400.5617,4542119990.6678,4550858374.7312,4559597551.3034,4568337518.9405,4577078276.2045,4585819821.6620,4594562153.8855,4603305271.4519,4612049172.9439,4620793856.9488,4629539322.0595,4638285566.8733,4647032589.9931,4655780390.0265,4664528965.5860,4673278315.2895,4682028437.7596,4690779331.6233,4699530995.5131,4708283428.0661,4717036627.9242,4725790593.7341,4734545324.1475,4743300817.8205,4752057073.4139,4760814089.5936,4769571865.0297,4778330398.3972,4787089688.3757,4795849733.6494,4804610532.9069,4813372084.8415,4822134388.1510,4830897441.5378,4839661243.7085,4848425793.3744,4857191089.2510,4865957130.0586,4874723914.5214,4883491441.3683,4892259709.3324,4901028717.1512,4909798463.5665,4918568947.3242,4927340167.1746,4936112121.8721,4944884810.1755,4953658230.8478,4962432382.6558,4971207264.3709,4979982874.7684,4988759212.6276,4997536276.7322,5006314065.8695,5015092578.8314,5023871814.4133,5032651771.4150,5041432448.6400,5050213844.8960,5058995958.9945,5067778789.7508,5076562335.9842,5085346596.5183,5094131570.1799,5102917255.7999,5111703652.2131,5120490758.2582,5129278572.7773,5138067094.6169,5146856322.6267,5155646255.6604,5164436892.5751,5173228232.2321,5182020273.4960,5190813015.2351,5199606456.3213,5208400595.6308,5217195432.0422,5225990964.4388,5234787191.7069,5243584112.7364,5252381726.4209,5261180031.6574,5269979027.3464,5278778712.3920,5287579085.7019,5296380146.1867,5305181892.7610,5313984324.3429,5322787439.8533,5331591238.2168,5340395718.3617,5349200879.2192,5358006719.7241,5366813238.8143,5375620435.4313,5384428308.5196,5393236857.0274,5402046079.9059,5410855976.1092,5419666544.5954,5428477784.3253,5437289694.2629,5446102273.3756,5454915520.6340,5463729435.0117,5472544015.4855,5481359261.0353,5490175170.6443,5498991743.2984,5507808977.9870,5516626873.7027,5525445429.4404,5534264644.1991,5543084516.9797,5551905046.7872,5560726232.6287,5569548073.5151,5578370568.4597,5587193716.4788,5596017516.5920,5604841967.8218,5613667069.1932,5622492819.7344,5631319218.4765,5640146264.4536,5648973956.7025,5657802294.2630,5666631276.1774,5675460901.4913,5684291169.2529,5693122078.5132,5701953628.3262,5710785817.7484,5719618645.8391,5728452111.6605,5737286214.2775,5746120952.7580,5754956326.1721,5763792333.5929,5772628974.0963,5781466246.7608,5790304150.6674,5799142684.9002,5807981848.5453,5816821640.6922,5825662060.4324,5834503106.8604,5843344779.0733,5852187076.1704,5861029997.2540,5869873541.4289,5878717707.8025,5887562495.4846,5896407903.5876,5905253931.2265,5914100577.5187,5922947841.5840,5931795722.5453,5940644219.5272,5949493331.6574,5958343058.0655,5967193397.8844,5976044350.2485,5984895914.2952,5993748089.1641,6002600873.9973,6011454267.9393,6020308270.1373,6029162879.7402,6038018095.9000,6046873917.7703,6055730344.5080,6064587375.2716,6073445009.2221,6082303245.5229,6091162083.3400,6100021521.8411,6108881560.1966,6117742197.5791,6126603433.1637,6135465266.1274,6144327695.6496,6153190720.9121,6162054341.0987,6170918555.3955,6179783362.9911,6188648763.0759,6197514754.8426,6206381337.4864,6215248510.2044,6224116272.1961,6232984622.6627,6241853560.8080,6250723085.8381,6259593196.9608,6268463893.3863,6277335174.3265,6286207038.9963,6295079486.6117,6303952516.3915,6312826127.5562,6321700319.3287,6330575090.9340,6339450441.5987,6348326370.5517,6357202877.0242,6366079960.2491,6374957619.4617,6383835853.8989,6392714662.7998,6401594045.4056,6410474000.9594,6419354528.7065,6428235627.8938,6437117297.7705,6445999537.5876,6454882346.5979,6463765724.0571,6472649669.2214,6481534181.3500,6490419259.7035,6499304903.5450,6508191112.1388,6517077884.7516,6525965220.6518,6534853119.1097,6543741579.3976,6552630600.7897,6561520182.5620,6570410323.9923,6579301024.3602,6588192282.9475,6597084099.0374,6605976471.9152,6614869400.8682,6623762885.1851,6632656924.1565,6641551517.0753,6650446663.2354,6659342361.9333,6668238612.4668,6677135414.1354,6686032766.2410,6694930668.0865,6703829118.9770,6712728118.2193,6721627665.1218,6730527758.9948,6739428399.1504,6748329584.9021,6757231315.5655,6766133590.4579,6775036408.8977,6783939770.2059,6792843673.7046,6801748118.7179,6810653104.5712,6819558630.5918,6828464696.1088,6837371300.4529,6846278442.9563,6855186122.9531,6864094339.7786,6873003092.7704,6881912381.2673,6890822204.6098,6899732562.1399,6908643453.2015,6917554877.1396,6926466833.3018,6935379321.0362,6944292339.6930,6953205888.6242,6962119967.1829,6971034574.7240,6979949710.6041,6988865374.1810,6997781564.8145,7006698281.8658,7015615524.6973,7024533292.6734,7033451585.1601,7042370401.5243,7051289741.1349,7060209603.3626,7069129987.5788,7078050893.1570,7086972319.4722,7095894265.9006,7104816731.8203,7113739716.6102,7122663219.6516,7131587240.3267,7140511778.0190,7149436832.1139,7158362401.9980,7167288487.0596,7176215086.6884,7185142200.2752,7194069827.2125,7202997966.8943,7211926618.7160,7220855782.0742,7229785456.3674,7238715640.9948,7247646335.3578,7256577538.8585,7265509250.9010,7274441470.8902,7283374198.2330,7292307432.3372,7301241172.6124,7310175418.4690,7319110169.3195,7328045424.5768,7336981183.6564,7345917445.9743,7354854210.9478,7363791477.9961,7372729246.5391,7381667515.9987,7390606285.7975,7399545555.3601,7408485324.1117,7417425591.4797,7426366356.8917,7435307619.7774,7444249379.5678,7453191635.6947,7462134387.5916,7471077634.6934,7480021376.4360,7488965612.2565,7497910341.5936,7506855563.8870,7515801278.5780,7524747485.1089,7533694182.9232,7542641371.4657,7551589050.1828,7560537218.5217,7569485875.9309,7578435021.8605,7587384655.7618,7596334777.0867,7605285385.2889,7614236479.8231,7623188060.1456,7632140125.7133,7641092675.9848,7650045710.4197,7658999228.4788,7667953229.6244,7676907713.3191,7685862679.0282,7694818126.2167,7703774054.3516,7712730462.9008,7721687351.3335,7730644719.1201,7739602565.7320,7748560890.6418,7757519693.3234,7766478973.2519,7775438729.9030,7784398962.7546,7793359671.2849,7802320854.9732,7811282513.3001,7820244645.7481,7829207251.7997,7838170330.9389,7847133882.6513,7856097906.4227,7865062401.7413,7874027368.0949,7882992804.9735,7891958711.8682,7900925088.2703,7909891933.6728,7918859247.5702,7927827029.4575,7936795278.8308,7945763995.1873,7954733178.0259,7963702826.8456,7972672941.1472,7981643520.4325,7990614564.2036,7999586071.9649,8008558043.2207,8017530477.4774,8026503374.2413,8035476733.0210,8044450553.3249,8053424834.6636,8062399576.5480,8071374778.4900,8080350440.0032,8089326560.6014,8098303139.8000,8107280177.1152,8116257672.0641,8125235624.1655,8134214032.9383,8143192897.9028,8152172218.5805,8161151994.4935,8170132225.1650,8179112910.1198,8188094048.8828,8197075640.9804,8206057685.9400,8215040183.2897,8224023132.5588,8233006533.2776,8241990384.9770,8250974687.1898,8259959439.4485,8268944641.2876,8277930292.2422,8286916391.8479,8295902939.6424,8304889935.1629,8313877377.9489,8322865267.5397,8331853603.4767,8340842385.3010,8349831612.5560,8358821284.7848,8367811401.5319,8376801962.3433,8385792966.7649,8394784414.3441,8403776304.6294,8412768637.1698,8421761411.5155,8430754627.2173,8439748283.8273,8448742380.8986,8457736917.9844,8466731894.6397,8475727310.4198,8484723164.8814,8493719457.5816,8502716188.0788,8511713355.9318,8520710960.7012,8529709001.9475,8538707479.2324,8547706392.1186,8556705740.1697,8565705522.9504);

var n,i,m,j:longint;
    re:array[1..10] of longint;
    s:real;
begin
     read(n);
     dec(n);
     for j:=0 to 1000 do
         if a[j]>=n then break;
     dec(j);
     if j<0 then j:=0;
     s:=a[j];
     j:=j*1000000;
     while s<n+1 do
     begin
          if s>=n then
          begin
               m:=m+1; re[m]:=j;
          end;
          j:=j+1;
          s:=s+ln(j)/ln(10);
     end;
     if m>0 then
     begin
          writeln(m);
          for j:=1 to m do writeln(re[j]);
     end
     else writeln('NO');
end.

Code mẫu của RR

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
using namespace std;

const double PI = acos(-1.0);
const double e = 2.71828183;

ll nDig(int x) {
    if (x <= 3) return 1;
    return (ll) (1. + floor(log10(x*PI*2)/2 + log10(x/e) * x));
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ll k; cin >> k;

    int Left, Right, l, r;

    // Left
    l = 0, r = 1000111000; Left = r;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (nDig(mid) >= k) {
            Left = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }

    // Right
    l = 0, r = 1000111000; Right = l;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (nDig(mid) <= k) {
            Right = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }

    if (nDig(Left) != k) {
        puts("NO");
        return 0;
    }
    cout << Right - Left + 1 << endl;
    FOR(i,Left,Right) printf("%d\n", i);
    return 0;
}

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>
#include <math.h>
#define Pi  3.14159265
#define e  2.71828183

double u,v,m,r;
int so;

void luythua(int k)
{
     if(k==1)
     {
          u = v;
     }
     else if(k%2==0)
     {
          luythua(k/2);
          u = u*u;
          so = so*2;
     }
     else
     {
          luythua (k/2);
          u = u*u*v;
          so = so*2;
     }
     while(u>10)
     {
         u=u/10;
         so++;
     }      
}

int f(int x)
{
    m = sqrt(2*Pi*x);
    v = (x/e);
    so = 0;
    luythua(x);
    u = u*m;
    while(u>10)
     {
         u=u/10;
         so++;
     } 
    return so+1;   
}

int main()
{
    int n;
    double Q=1;
    int t=0,a[4];
    //while(scanf("%d",&n)>0)
        //printf("%d\n",f(n));
    scanf("%d",&n);
    if(n<100000)
    {
    for(int i = 1;;i++)
    {
        Q = Q*i;    
        while(Q>=1)
        {
            Q = Q/10;
            n--;
        }
        if(Q<1 && n==0)
        {
            t++;
            a[t] = i;
        }
        if(n<0)
             break;
    }
    if(t==0)
        printf("NO");
    else
    {
        printf("%d\n",t);
        for(int i = 1;i<=t;i++)
            printf("%d\n",a[i]);
    }
    }
    else
    {
        int U = 1,V=n;
        while(V-U>1)
        {
            int r = (U+V)/2;
            if(f(r)>n)
                V = r;
            else U = r;
        }
        if(f(U)!=n)
        {
             printf("NO");
             //printf("%d",u);
        }
        else
        {
            printf("1\n");
            printf("%d",U);
        }
    }
    //getch();
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.