求助高精度输出不正确

P1591 阶乘数码

BearBig @ 2022-07-04 16:47:40

闰土

#include<bits/stdc++.h>
using namespace std;
struct var
{
    int src[1000];
    var(string num)
    {
        memset(src,0,sizeof(src));
        for(int i=0;i<num.length();++i)
            src[1000-num.length()+i]=num[i]-'0';
    }
    int &operator[](int ind){return src[ind];}
};
var operator*(var a,int b)
{
    for(int i=0;i<1000;++i)
        a[i]*=b;
    for(int i=998;i>=0;--i)
    {
        a[i]+=a[i+1]/10;
        a[i+1]%=10;
    }
    return a;
}
ostream& operator<<(ostream& cout,var b)
{
    for(int i=0;i<1000;++i)
        if(b[i]!=0)
            for(int j=i;j<1000;++j)
                cout<<b[j];
    return cout;
}
int main()
{
    int t;cin>>t;while(t--)
    {
        int n,a,cnt(0);cin>>n>>a;
        var big("1");
        for(int i=1;i<=n;++i)
            big=big*i;
        for(int i=0;i<1000;++i)
            if(big[i]!=0)
                for(int j=i;j<1000;++j)
                    if(big[j]==a)++cnt;
        cout<<cnt<<endl;
    }
}

by MC小萌新 @ 2022-07-04 16:52:45

闰土你好我是猹


by HappyCode @ 2022-07-04 16:56:38

参考一下 蒟蒻的模板?

istream& operator>>(istream& cin,num& a){
    string s;
    cin>>s;
    a.length=s.length();
    for(int i=a.length-1;i>=0;i--){
        a.value[a.length-i]=s[i]-'0';
    }
    return cin;
}
ostream& operator<<(ostream& cout,num a){
    for(int i=max(1,a.length);i>=1;i--){
        cout<<a.value[i];
    }
    return cout;
}

具体高精度请看 博客


by Alex_wcq @ 2022-07-04 17:00:43

HC 承认自己是神!!1


|