第一行:十进制高精度数2^P-1的位数。
第2-11行:十进制高精度数2^P-1的最后500位数字。(一行输出,不足500位时高位补0)
不必验证2^P-1与P是否为素数。
input:
1279
output:
386
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000104079321946643990819252403273640855
38615262247266704805319112350403608059673360298012
23944173232418484242161395428100779138356624832346
49081399066056773207629241295093892203457731833496
61583550472959420547689811211693677147548478866962
50138443826029173234888531116082853841658502825560
46662248318909188018470682222031405210266984354887
32958028878050869736186900714720710555703168729087
【参考程序】:
#include<iostream>
#include<cmath>
using namespace std;
int a[502];
int n;
void work(int p)
{
int b[1001];
if (p==1)
{
a[1]=2;
return ;
}
memset(b,0,sizeof(b));
if (p%2==1)
{
work(p/2);
for (int i=1;i<=500;i++)
for (int j=1;j<=500;j++)
b[i+j-1]+=a[i]*a[j];
for (int i=1;i<=501;i++)
{
a[i]=b[i]*2;
a[i]+=a[i-1]/10;
a[i-1]%=10;
}
}
else
{
work(p/2);
for (int i=1;i<=500;i++)
for (int j=1;j<=500;j++)
b[i+j-1]+=a[i]*a[j];
for (int i=1;i<=501;i++)
{
a[i]=b[i]+a[i-1]/10;
a[i-1]%=10;
}
}
a[501]=0;
}
int main()
{
scanf("%d",&n);
printf("%0.0lf\n",floor(n*log(2.0)/log(10.0))+1);
work(n);
for (int i=500;i>=2;i--) printf("%d",a[i]);
printf("%d\n",a[1]-1);
return 0;
}