思路 :
- 这段代码只能C++ 17的64位版本或者20的64位版本,否则会CE
- a i = g a i + 1 a_i = g^{a_{i+1}} ai=gai+1,且样例给了上界的答案,所以倒推
- long long会爆,所以要用__int128
- __int128的输入输出方式
- long long x = 1e18 + 31 cout x会得到1000(省略0),也就是说爆了,
- double x = 1e18 + 31 cout x会得到1e+18,printf x会得到1000000000000000000.000000
#include <iostream>
using namespace std;
typedef __int128 ll;
const int N = 1e6 + 10;
//const ll mod = 1e18 + 31; wa!!不要用浮点数表示整数
const ll mod = 1000000000000000031;
ll f[N];
ll qmi(ll a, ll b, ll q)
{
ll res = 1 % q;
while (b)
{
if (b & 1) res = res * a % q;
a = a * (ll)a % q;
b >>= 1;
}
return res;
}
inline __int128 read()
{
__int128 x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void print(__int128 x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9)
print(x / 10);
putchar(x % 10 + '0');
}
int main()
{
int n = 1e6;
f[n] = 300;
for (int i = n - 1; i >= 0; i -- )
f[i] = qmi(42ll, f[i + 1], mod);
int x;
cin >> x;
print(f[x]);
return 0;
}