before_the_dawn @ 2024-08-17 16:24:53
#include<bits/stdc++.h>
using namespace std;
int aa[100000],bb[100000],cc[100000];
void gjd(int a[],int b[],int c[]){
memset(c,0,sizeof(c));
for(int x=1;x<=500;x++)
{
for(int y=1;y<=500;y++)
{
if(a[x]*b[y]+c[x+y-1]>=10)
c[x+y]+=(a[x]*b[y]+c[x+y-1])/10;
c[x+y-1]=(a[x]*b[y]+c[x+y-1])%10;
}
}
for(int i=1;i<=500;i++){
a[i]=c[i];
}
}
int main()
{
aa[1]=1;
bb[1]=2;
long long n;
cin >> n;
cout << (int)(log10(2)*n+1) << endl;
while(n){
if(n&1)
{
gjd(aa,bb,cc);
}
gjd(bb,bb,cc);
n >>=1;
}
aa[1]-=1;
for(int x=500;x>0;x--)
{
if(x%50==0&&x!=500) cout << endl;
cout << aa[x];
}
return 0;
}
by jiang_yitao @ 2024-10-11 19:36:53
@before_the_dawn 看一下我的
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
#include <string.h>
void mul(int* a, int* b)
{
int i, j, res[125];
memset(res, 0, sizeof(res));
for (i = 0; i < 125; i++)
for (j = 0; j < 125 - i; j++)
{
res[i + j] += a[i] * b[j];
res[i + j + 1] += res[i + j] / 10000;
res[i + j] %= 10000;
}
memcpy(a, res, sizeof(res));
}
int p, result[125], base[125];
int main()
{
int i;
scanf("%d", &p);
printf("%d\n", (int)(p * log10(2.0)) + 1);
result[0] = 1;
base[0] = 2;
while (p)
{
if (p & 1)
mul(result, base);
p >>= 1;
mul(base, base);
}
result[0]--;
for (i = 124; i >= 0; i--)
if (i % 25 == 12)
printf("%02d\n%02d", result[i] / 100, result[i] % 100);
else
{
printf("%04d", result[i]);
if (i % 25 == 0)printf("\n");
}
return 0;
}
求关注