这题的数据实在是太大了
使用__int 128
至于啥是__int 128,我想聪明的你一定知道。
AC代码(附保姆级题解):
#include <bits/stdc++.h>
using namespace std;
typedef __int128 lll; //这个功能很不错
lll f[20], mother[20], son[20];
//f存斐波那契数列
//mother存分母
//son存分子
//__int128不能直接输出
//这个是输出板子
void print(lll x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9) print(x / 10);
putchar (x % 10 + '0');
}
int main()
{
f[1] = f[2] = 1;
for (int i = 3; i <= 15; i ++)
f[i] = f[i - 1] + f[i - 2]; //算出斐波那契并存在里面
for (int i = 1; i <= 13; i ++)
mother[i] = f[i] * f[i+1]; //递推算出分母
lll common = 1; //防止分母变成0
for (int i = 1; i <= 13; i ++)
{
common *= mother[i]; //分母乘分母
son[i] = 1;
}
//这时common已经变成了最大公倍分母
for (int i = 1; i <= 13; i ++)
{
lll cur = common / mother[i]; //通分操作
son[i] *= cur; //每个分子乘以除自己分母以外的分母
}
lll ans = 0;
for (int i = 1; i <= 13; i ++)
ans += son[i]; //通分完的分子相加
lll g = __gcd(common, ans); //求最大公约数g
common /= g; //分母约分
ans /= g; //分子约分
print(ans);
cout << "/";
print(common);
return 0;
}