高精度 hdu 2940 Hex Factorial

来源:互联网 发布:seo研究中心是什么 编辑:程序博客网 时间:2024/06/06 04:23

直接暴力打表,也可以在代码外打表复制粘贴

#include<cstdio>#include<cstring>#include<cmath>using namespace std;const int BIT = 16;struct BIGint{    int bit[200];    void MEMset(){        memset(bit,0,sizeof(bit));        bit[1] = 1;    }    void multiply(int n){        int tmp;        for (int i = 1;i < 200;++i)            bit[i] *= n;        for (int i = 1;i < 200;++i)            if (tmp = bit[i] / BIT){                bit[i] %= BIT;                bit[i+1] += tmp;            }    }    int CountZore(){        int i = 199,ans(0);        while( !bit[i--] );        while(i) if(!bit[i--])ans++;        return ans;    }}bigInt;int ans[110];void init(){    memset(ans,0,sizeof(ans));    bigInt.MEMset();    for (int i = 2;i <= 101;++i){        bigInt.multiply(i);        ans[i] = bigInt.CountZore();    }}int main (){    init();    int n;    while(~scanf("%d",&n) && n >= 0)        printf("%d\n",ans[n]);    return 0;}


0 0
原创粉丝点击