欧拉降幂裸题
a^b mod c = a ^ (b mod φ(c) - φ(c)) mod c;
题目 输入n 求 2^(n-1) mod 1e9+7
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#include <algorithm>
#include <queue>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <fstream>
#include <ctime>
#pragma warning(disable:4996);
#define mem(sx,sy) memset(sx,sy,sizeof(sx))
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-8;
const double PI = acos(-1.0);
const ll llINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
using namespace std;
ll mod = 1e9 + 7;
ll qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main() {
char str[1000010];
int T;
scanf("%d", &T);
while (T--) {
scanf("%s", str);
ll phic = mod - 1;
int i, len = strlen(str);
ll res = 0;
for (i = 0; i < len; i++) {
res = res * 10 + str[i] - '0';
if (res > phic) break;
}
if (i == len) {
printf("%lld\n", qpow(2, res - 1));
}
else {
res = 0;
for (i = 0; i < len; i++) {
res = res * 10 + str[i] - '0';
res %= phic;
}
printf("%lld\n", qpow(2, (res - 1) + (mod - 1)));
}
}
}