cmaths @ 2021-09-20 14:10:45
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
int base[1010], res[1010], fl = 1, rl = 1;
void gjtimes()
{
int resl = std::min(fl + rl, 500), calres[1010] = {0};
for(int i = 1; i <= fl; i++)
for(int j = 1; j <= rl; j++)
calres[i + j - 1] += base[i] * res[j];
for(int i = 1; i <= resl; i++)
{
calres[i + 1] += calres[i] / 10;
calres[i] %= 10;
res[i] = calres[i];
}
rl = resl;
}
void gjpow2()
{
int resl = std::min(2 * fl, 500);
int copy[1010] = {0}, calres[1010] = {0};
for(int i = 1; i <= fl; i++)
copy[i] = base[i];
for(int i = 1; i <= fl; i++)
for(int j = 1; j <= rl; j++)
calres[i + j - 1] += base[i] * copy[j];
for(int i = 1; i <= resl; i++)
{
calres[i + 1] += calres[i] / 10;
calres[i] %= 10;
base[i] = calres[i];
}
fl = resl;
}
int main()
{
base[1] = 2;
res[1] = 1;
int n;
scanf("%d", &n);
printf("%d\n", (int)(log10(2) * n + 1));
while(n)
{
if(n & 1)
gjtimes();
gjpow2();
n >>= 1;
}
res[1] -= 1;
for(int i = 500; i >= 1; i--)
printf("%d", res[i]);
return 0;
}
谢谢各位神犇!
by mingw64 @ 2021-09-23 20:40:50
需要每十个数换一行
by mingw64 @ 2021-09-23 20:41:35
(每行输出50位,共输出10行,不足500位时高位补0) 题目里面有
by cmaths @ 2021-09-25 13:19:45
@UnknownHostException 我眼瞎,谢谢orz