50分求助

P1045 [NOIP2003 普及组] 麦森数

aa_2315 @ 2023-11-24 10:59:12

#include<iostream>
#include<string>
using namespace std;
int p, t = 1, arr[1000000] = { 0,1 };
int main()
{
    scanf("%d",&p);
    for (int i = 1; i <= p; i++)
    {
        for (int j = 1; j <= t; j++)
        {
            arr[j] *= 2;
        }
        for (int j = 1; j <= t; j++)
        {
            if (arr[j] > 9)
            {
                arr[j + 1]+= arr[j] / 10;
                arr[j] %= 10;
                if (j + 1 > t)
                    t++;
            }
        }
    }
    printf("%d\n",t);
    arr[1] -= 1;
    for (int i =500; i >= 1; i--)
    {
        if (i % 50 == 0 && i != 500)
            printf("\n");
    printf("%d",arr[i]);

    }
}

|