1046 A^B Mod C
来源:互联网 发布:51模拟器官网mac 编辑:程序博客网 时间:2024/05/16 01:11
1046 A^B Mod C
基准时间限制:1 秒 空间限制:131072 KB 分值:
给出3个正整数A B C,求A^B Mod C。
例如,3 5 8,3^5 Mod 8 = 3。
Input
3个正整数A B C,中间用空格分隔。(1 <= A,B,C <= 10^9)
Output
输出计算结果
Input示例
3 5 8
Output示例
3
A ^ B MOD C = A ^ (B % Phi(C) + Phi(C)) Mod C (B >= Phi(C))
Phi(C)为欧拉函数,指小于等于C的且与C互质的数的个数
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <string>#include <cmath>#include <set>#include <queue>#include <algorithm>#include <vector>using namespace std;#define esp 1e-8const double PI = acos(-1.0);const int inf = 1000000005;const long long mod = 1000000007;//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中long long A, B, C;long long eular(long long x){long long res = x;long long ans = x;for (int i = 2; i * i <= x; ++ i){if (res % i == 0)ans = ans / i * (i - 1);while (res % i == 0)res /= i;}if (res > 1)ans = ans / res * (res - 1);return ans;}long long power(long long a, long long b){long long res = 1;while (b){if (b & 1)res = res * a % C;b >>= 1;a = a * a % C;}return res % C;}int main(){while (cin >> A >> B >> C){long long x = (B % eular(C) + eular(C));//cout << eular(C) << endl;if (B >= eular(C))cout << power(A, x) << endl;elsecout << power(A, B) << endl;}}
0 0
- 1046 A^B Mod C
- 1046 A^B Mod C
- 1046 A^B Mod C
- 1046 A^B Mod C
- 1046 A^B Mod C
- A^B mod C
- A^B mod C
- A^B mod C
- 51nod 1046 A^B Mod C
- 51nod 1046 A^B Mod C
- 51nod 1046 A^B Mod C
- 51nod 1046 A^B Mod C
- 51nod 1046 A^B Mod C
- 51Nod 1046 A^B Mod C
- 51nod 1046 A^B Mod C
- 51Nod 1046 A^B Mod C
- BIT1044 A^B mod C
- 求a^b mod c
- 类模板的定义及其使用
- Spring事务管理
- 简单就是美——由模式谈面向对象的基本原则之单一职责原则
- HDU Human Gene Functions
- Linux下环境变量的设置
- 1046 A^B Mod C
- HDU 寒冰王座
- HDU 最大报销额
- 硬盘结构及接口类型
- 与构架有关的几个基本概念
- linux内核用户地址空间分配与管理
- android ocr 身份证识别
- 命令行操作中遇到的找不到文件的错误
- 第五周项目1:三角形类雏形(5)