比赛 2025.1.4 评测结果 TTAAAAATTT
题目名称 麦森数 最终得分 50
用户昵称 健康铀 运行时间 10.102 s
代码语言 C++ 内存使用 2.58 MiB
提交时间 2025-01-04 17:59:51
显示代码纯文本
#include<cstdio>  
#include<cmath>  
#include<cstring>  
using namespace std;  
const long long mod = 10000000000;  

using namespace std;  

const int N = 1e5 + 10;  

int P, l = 1, lb = 1;  

int a[N] = {}, b[N] = {}, c[N] = {};  

int cheng1() {  
    memset(c, 0, sizeof(c));  
    for (int i = 1; i <= l; ++i) {  
        for (int j = 1; j <= lb; ++j) {  
            c[i + j - 1] += a[i] * b[j];  
            c[i + j] += (c[i + j - 1]) / 10;  
            c[i + j - 1] %= 10;  
        }  
    }  
    int lc = l + lb;  
    while (c[lc] == 0) --lc;  
    for (int i = 1; i <= lc; ++i) {  
        a[i] = c[i];  
    }  
    return lc;  
}  

int cheng2() {  
    memset(c, 0, sizeof(c));  
    for (int i = 1; i <= lb; ++i) {  
        for (int j = 1; j <= lb; ++j) {  
            c[i + j - 1] += b[i] * b[j];  
            c[i + j] += (c[i + j - 1]) / 10;  
            c[i + j - 1] %= 10;  
        }  
    }  
    int lc = lb + lb;  
    while (c[lc] == 0) --lc;  
    for (int i = 1; i <= lc; ++i) {  
        b[i] = c[i];  
    }  
    return lc;  
}  

void power() {  
    while (P) {  
        if (P & 1) l = cheng1();  
        P >>= 1;  
        lb = cheng2();  
    }  
}  

int main() { 
freopen("mason.in","r",stdin);
freopen("mason.out","w",stdout); 
    memset(a, 0, sizeof(a));  
    memset(b, 0, sizeof(b));  
    scanf("%d", &P);  
    a[1] = 1;  
    b[1] = 2;  
    power();  
    printf("%d\n", l);  
    --a[1];  
    for (int i = 500; i >= 1; --i) {  
        printf("%d", a[i]);  
        if (!((i - 1) % 50)) printf("\n");  
    }  
    return 0;  
}