0分求助
查看原帖
0分求助
706974
zcs_kim楼主2023/12/20 20:49

代码:

#include <bits/stdc++.h>
using namespace std;
string s, t;
int a[100005], b[100005], c[100005], n;
void make(int x[], string v)
{
	x[0] = v.size();
	for(int i = 0; i < int(v.size()); i++) x[x[0] - i] = v[i] - '0';
}
void minus_big(int x[], int y[]) //x > y 
{
	x[0] = max(x[0], y[0]);
	for(int i = 1; i <= x[0]; i++)
	{
		while(x[i] < y[i])
		{
			x[i + 1]--;
			x[i] += 10;
		}
		x[i] -= y[i];
	}
	while(x[x[0]] == 0 && x[0] > 1)
		x[0]--;
}
void time_big(int x[], int y[], int z[])
{
	z[0] = x[0] + y[0] - 1;
	for(int i = 1; i <= x[0]; i++)
	{
		for(int j = 1; j <= y[0]; j++)
		{
			z[i + j - 1] += x[i] * y[j];
			while(z[i + j - 1] > 9)
			{
				z[i + j - 1] -= 10;
				z[i + j]++;
			}
		}
	}
	while(z[z[0] + 1] > 0)
	{
		z[0]++;
		while(z[z[0]] > 9)
		{
			z[z[0]] -= 10;
			z[z[0] + 1]++;
			z[0]++;
		}
	}
}
void print_big(int x[])
{
	for(int i = x[0]; i >= 1; i--) cout << x[i];
	cout << endl;
}
int main()
{
	cin >> n;
	make(a, "1");
	make(b, "2");
	for(int i = 1; i <= n; i++)
	{
		if(i % 2) time_big(a, b, c);
		else time_big(c, b, a); 
	}
	if(n % 2)
	{
		make(b, "1");
		minus_big(c, b);
		make(b, "2");
		time_big(c, b, a);
		print_big(a);
	}
	else
	{
		make(b, "1");
		minus_big(a, b);
		make(b, "2");
		time_big(a, b, c);
		print_big(c);
	}
	return 0;
}
2023/12/20 20:49
加载中...