'commit'
This commit is contained in:
51
TangDou/Topic/P5091.cpp
Normal file
51
TangDou/Topic/P5091.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
const int N = 2000010;
|
||||
|
||||
// 求单个数字的欧拉函数
|
||||
int phi(int x) {
|
||||
int res = x;
|
||||
for (int i = 2; i <= x / i; i++)
|
||||
if (x % i == 0) {
|
||||
res = res / i * (i - 1);
|
||||
while (x % i == 0) x /= i;
|
||||
}
|
||||
if (x > 1) res = res / x * (x - 1);
|
||||
return res;
|
||||
}
|
||||
|
||||
// 快速幂
|
||||
int qmi(int a, int b, int p) {
|
||||
int res = 1;
|
||||
a %= p;
|
||||
while (b) {
|
||||
if (b & 1) res = res * a % p;
|
||||
b >>= 1;
|
||||
a = a * a % p;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
signed main() {
|
||||
int a, c;
|
||||
cin >> a >> c;
|
||||
int p = phi(c);
|
||||
|
||||
// 将非数字字符,比如空格读没
|
||||
char ch;
|
||||
ch = getchar();
|
||||
while (ch < '0' || ch > '9') ch = getchar();
|
||||
|
||||
// 当是数字字符时,一直读入
|
||||
int b = 0;
|
||||
while (ch >= '0' && ch <= '9') {
|
||||
b = b * 10 + ch - '0';
|
||||
if (b >= p) // 检查b是否大于等于phi(c)
|
||||
b = b % p + p;
|
||||
// 继续读入下一个字符
|
||||
ch = getchar();
|
||||
}
|
||||
printf("%lld\n", qmi(a, b, c)); // 按快速幂来计算就行了
|
||||
}
|
||||
Reference in New Issue
Block a user