这道题需要用快速幂,不过,因为n太大了,需要费马小定理来降幂。
然后,这题有个坑,题中没说,这里需要多组输入。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll qpow(ll p, ll x)
{
ll ans = 1;
while (p)
{
if (p & 1)ans = (ans * x) % MOD;
x = (x *x)% MOD;
p >>= 1;
}
return ans;
}
int main()
{
string s;
while (cin >> s)
{
ll p = 0;
for (ll i = 0; i < s.size(); i++) {
p = (p * 10 + s[i] - '0') % (MOD - 1);
//cout << p << endl;
}
cout << qpow((p - 1 + MOD - 1) % (MOD - 1), 2) << endl;
}
return 0;
}