20分 tle+wa求教

P1045 [NOIP2003 普及组] 麦森数

Zhouyuan0father @ 2022-04-29 18:35:13

#include <bits/stdc++.h>
using namespace std;
int y = 1;
int a1[50000000];
void gaojin(int a) {
    for (int i = 0; i < y; i++) {
        a1[i] = a1[i] * 2;
    }
    for (int i = 0; i < y; i++) {
        if (a1[i] > 9&&y<500) {
            if(i==y-1) y++;
            a1[i + 1]++;
            a1[i] %= 10;
        }
    }
}
int main() {
    int a;
    cin >> a;
    a1[0] = 1;
    for (int i = 1; i <= a; i++) {
        gaojin(i);
    }
    int ans;
    ans=a*log10(2)+1;
    cout <<ans<< endl;
    int q = 0;
    for (int i = 499; i >= 0; i--) {
        if(i==0){
            cout<<a1[i]-1;
            break;
        }
        cout << a1[i];
        q++;
        if (q == 50) {
            cout << endl;
            q = 0;
        }
    }
    return 0;
}

by yanghaolin @ 2022-05-03 11:10:22

SB


by ZhangZiqiRoyce @ 2022-05-03 11:46:49

@yanghaolin 已举报!严惩不贷! (正道的光~照在了大地上, 把每个~黑暗的地方,全部都照亮)


by yanghaolin @ 2022-05-03 11:59:41

@ZhangZiqiRoyce 已举报!严惩不贷! (正道的光~照在了大地上, 把每个~黑暗的地方,全部都照亮)


by yanghaolin @ 2022-05-03 12:00:43

SB=sweet baby


by ZhangZiqiRoyce @ 2022-05-03 15:54:14

@yanghaolin 歪曲事实,屡教不改,再次举报!


|