这道题怎么用Python写打表代码?

P1009 [NOIP1998 普及组] 阶乘之和

AC_love @ 2023-07-24 14:20:41

因为是单个输入且这个输入比较小,我考虑用打表解决问题

但是如果用计算器一个一个按,比较麻烦,而且也会被计算器精度限制

考虑到Python没有精度限制,我想要用Python来写一份打表代码

但是我并不会Python这门语言,请问有没有大佬告诉我Python怎么用类似freopen的方式输出一个txt文本,以便于我打表的时候复制?


by xiaoyang111 @ 2023-07-24 14:24:02

https://baijiahao.baidu.com/s?id=1765230658139253625&wfr=spider&for=pc


by xiaoyang111 @ 2023-07-24 14:25:09

我一个红名连freopen都没有接触过


by xiaoyang111 @ 2023-07-24 14:28:02

帮你打了

#include <iostream>
using namespace std;
int main(){
    string a[]={"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"};
    int t;
    cin >> t;
    cout<<a[t-1]<<endl;
    return 0;
}

by Weizhuo_Zhao @ 2023-07-24 14:35:03

@xiaoyang111 人家说PY---没说C++。。。你真是个朵拉!


by xiaoyang111 @ 2023-07-24 14:36:53

@Weizhuo_Zhao 我看他用的是C++20语言啊,他应该是想交C++语言吧。那个网址是python的啊况且我之前python学过1年了的


by xiaoyang111 @ 2023-07-24 14:37:48

py的表的话改一下也可以啊


by Weizhuo_Zhao @ 2023-07-24 14:38:50

@xiaoyang111 但是他她它说的是Py啊!并且打表还不如自己做


by Weizhuo_Zhao @ 2023-07-24 14:39:36

@xiaoyang111 我不管多么努力✊做题都提不了分...还是蓝名


by xiaoyang111 @ 2023-07-24 14:39:41

s=["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"]
n=int(input())
print(s[n-1])

by xiaoyang111 @ 2023-07-24 14:40:16

@Weizhuo_Zhao 打比赛啊,抢题解也行啊


| 下一页