1 条题解

  • 0
    @ 2025-10-8 16:51:22

    G02 高精度快速幂

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    struct node
    {
        int a[511];
        node(){memset(a,0,sizeof(a));}
    };
    
    node operator* (node A,node B)
    {
        node C;
        for(int i=1;i<=500;i++)
            for(int j=1;j<=500;j++)if(i+j-1<=500)
                C.a[i+j-1]=C.a[i+j-1]+A.a[i]*B.a[j];
        for(int i=1;i<=500;i++) C.a[i+1]+=C.a[i]/10,C.a[i]%=10;
        return C;
    }
    node qpow(node A,int b)
    {
    	node C;C.a[1]=1;
    	for(;b;b>>=1)
    	{
    		if(b&1)C=C*A; 
    		A=A*A;
    	}
    	return C;
    }
    int main()
    {
        int p;scanf("%d",&p);
        printf("%d\n",int(p*log10(2))+1);
        node A;A.a[1]=2;
        A=qpow(A,p);A.a[1]--; 
        for(int i=500;i>=1;i--)printf("%d",A.a[i]);
        return 0;
    }
    
    • 1

    G02*【快速幂】高精度快速幂[NOIP普及组2003]麦森数

    信息

    ID
    111
    时间
    1000ms
    内存
    128MiB
    难度
    6
    标签
    递交数
    136
    已通过
    44
    上传者