Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000).

Input

There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space.

Output

For each testcase, output an integer, denotes the result of A^B mod C.

Sample Input

3 2 4
2 10 1000

Sample Output

1
24 思路:欧拉降幂板子
typedef long long LL;

LL A, C;
char B[]; LL getEuler(LL x) {
LL ans = x;
for(LL i = ; i*i <= x; ++i) {
if(x % i == ) {
ans = ans / i * (i-);
while(x % i == ) x /= i;
}
}
if(x > ) ans = ans / x * (x-);
return ans;
} LL quickPow(LL a, LL b, LL p) { // a^b (modp)
LL ret = ;
while(b) {
if(b & ) ret = (ret * a) % p;
a = (a * a) % p;
b >>= ;
}
return ret;
} int main() {
ios::sync_with_stdio(false), cin.tie(NULL);
while(cin >> A >> B >> C) {
LL phi = getEuler(C);
LL num = ;
int len = strlen(B);
for(int i = ; i < len; ++i) {
num = (num * + B[i] - '');
if(num >= phi) break;
}
if(num >= phi) {
num = ;
for(int i = ; i < len; ++i)
num = (num * + B[i] - '') % phi;
cout << quickPow(A, num+phi, C) << "\n";
} else {
cout << quickPow(A, num, C) << "\n";
}
} return ;
}
												

Day7 - B - Super A^B mod C FZU - 1759的更多相关文章

  1. FZU Super A^B mod C(欧拉函数降幂)

    Problem 1759 Super A^B mod C Accept: 878    Submit: 2870 Time Limit: 1000 mSec    Memory Limit : 327 ...

  2. FZU 1759 Super A^B mod C 指数循环节

    Problem 1759 Super A^B mod C Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description G ...

  3. FOJ ——Problem 1759 Super A^B mod C

     Problem 1759 Super A^B mod C Accept: 1368    Submit: 4639Time Limit: 1000 mSec    Memory Limit : 32 ...

  4. fzou 1759 Super A^B mod C

    Problem 1759 Super A^B mod CAccept: 456    Submit: 1488Time Limit: 1000 mSec    Memory Limit : 32768 ...

  5. FZU 1759 题解 欧拉降幂

    本题考点:欧拉降幂 Super A^B mod C Given A,B,C, You should quickly calculate the result of A^B mod C. (1<= ...

  6. FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...

  7. Super A^B mod C (快速幂+欧拉函数+欧拉定理)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 题目:Problem Description Given A,B,C, You should quick ...

  8. Super A^B mod C

    Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...

  9. K - Super A^B mod C

    Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...

随机推荐

  1. C++运算符重载复习

    本人理解运算符重载实质 就类似函数重载   运算符重载都可以写成一个函数 里面传入参数 来调用 运算符重载不是必须的 但是重载后会方便很多. 小例子 一个类实现 ++  和+某个数重载 大于号重载  ...

  2. 进程fork

    fork用于父进程创建一个子进程 返回两次 返回-1表示错误 父进程中返回创建子进程的ID,大于0 返回0是表示进入子进程 创建的子进程会继承父进程的属性,比如打开的文件描述符.工作目录.根目录等等. ...

  3. 吴裕雄--天生自然ORACLE数据库学习笔记:用户管理与权限分配

    create user mr identified by mrsoft default tablespace users temporary tablespace temp; create user ...

  4. 什么是Nib文件

    Nib文件是一种特殊类型的资源文件,它用于保存iPhone OS或Mac OS X应用程序的用户接口.Nib文件是Interface Builder文档.通常您会使用Interface Builder ...

  5. Django 学习之Django Rest Framework_序列化器_Serializer

    作用: 1.序列化,序列化器会把模型对象转换成字典,经过response以后变成json字符串. 2.反序列化,把客户端发送过来的数据,经过request以后变成字典,序列化器可以把字典转成模型. 3 ...

  6. SpringBoot 集成MyBatis、事务管理

    集成MyBatis (1)在pom.xml中添加依赖 <!-- mybatis的起步依赖.包含了mybatis.mybatis-spring.spring-jdbc(事务要用到)的坐标 --&g ...

  7. Spring Cloud入门-Nacos实现注册和配置中心(Hoxton版本)

    文章目录 摘要 Nacos简介 使用Nacos作为注册中心 安装并运行Nacos 创建应用注册到Nacos 负载均衡功能 使用Nacos作为配置中心 创建nacos-config-client模块 在 ...

  8. win7 X64 进程名称不一致,导致杀进程失效!

    win7 x86, 或 win10 x64 环境下, x86的进程名称 ”aaa.exe“ 在win7 x64下面显示为  ”aaa.exe *32“

  9. php后门拿下当前目录

    Weevely是一个模拟类似telnet的连接的隐形PHP网页shell.它是Web应用程序后期开发的必备工具,可以作为隐形后门程序,也可以作为一个web外壳来管理合法的Web帐户,甚至可以免费托管. ...

  10. 【剑指Offer面试编程题】题目1385:重建二叉树--九度OJ

    题目描述: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7 ...