考场黑科技(一)无耻打表

打表可耻,打表可耻,打表可耻,默念三遍保平安。

P1009 阶乘之和

 https://www.luogu.org/problemnew/solution/P1009

升级版 “暴力出奇迹,打表拿省一”

这题固然应该使用高精度来做,但是现场实现容易出错,适当变通下,借助JAVA来做(BigInteger类)。

比较短的直接输出在控制台就行了,数据量大的输出到文件里。

public static void main(String[] args) {
        BigInteger res=new BigInteger("1");
        BigInteger temp = new BigInteger(new Integer(0).toString());
        for(int i=2;i<=60;i++) {
            temp = temp.add(res);
            res = res.multiply(new BigInteger((new Integer(i)).toString()));;
            System.out.println("\""+temp+"\",");
            
        }
    }

于是便有了:

#include <iostream>
#include <string>
using namespace std;

string arr[] = {
"0",
"1",
"3",
"9",
"33",
"153",
"873",
"5913",
"46233",
"409113",
"4037913",
"43954713",
"522956313",
"6749977113",
"93928268313",
"1401602636313",
"22324392524313",
"378011820620313",
"6780385526348313",
"128425485935180313",
"2561327494111820313",
"53652269665821260313",
"1177652997443428940313",
"27029669736328405580313",
"647478071469567844940313",
"16158688114800553828940313",
"419450149241406189412940313",
"11308319599659758350180940313",
"316196664211373618851684940313",
"9157958657951075573395300940313",
"274410818470142134209703780940313",
"8497249472648064951935266660940313",
"271628086406341595119153278820940313",
"8954945705218228090637347680100940313",
"304187744744822368938255957323620940313",
"10637335711130967298604907294846820940313",
"382630662501032184766604355445682020940313",
"14146383753727377231082583937026584420940313",
"537169001220328488991089808037100875620940313",
"20935051082417771847631371547939998232420940313",
"836850334330315506193242641144055892504420940313",
"34289376947494122614363304694584807557656420940313",
"1439295494700374021157505910939096377494040420940313",
"61854558558074209658512637979453093884758552420940313",
"2720126133346522977702138448994068984204397080420940313",
"122342346998826717539665299944651784048588130840420940313",
"5624964506810915667389970728744906677010239883800420940313",
"264248206017979096310354325882356886646207872272920420940313",
"12678163798554051767172643373255731925167694226950680420940313",
"620960027832821612639424806694551108812720525606160920420940313",
"31035053229546199656252032972759319953190362094566672920420940313",
"1582153806516928479880495049442062531016450082111552784920420940313",
"82240328977460807051541131905845829506305955522994830608920420940313",
"4357123613037486371349554885295245479196649743889808555280920420940313",
"235200820952278866843442297568322826562475214315697749687568920420940313",
"12931604174610554792808543145134839786142796265765134511963408920420940313",
};

int main() {
    int n;
    cin >> n;
    cout << arr[n] << endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/caozicheng1999/p/10857852.html