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. 为小学生出四则运算题目.java

    import java.util.Scanner; import java.util.Random; public class test{ public static int s1 = new Ran ...

  2. linear-gradient()的用法

    linear-gradient() 函数用于创建一个线性渐变的 "图像" 它的语法是 background: linear-gradient(direction, color-st ...

  3. HashMap与HashTable源码学习及效率比较分析

    一.个人学习后的见解: 首先表明学习源码后的个人见解,后续一次依次进行分析: 1.线程安全:HashMap是非线程安全的,HashTable是线程安全的(HashTable中使用了synchroniz ...

  4. github设置分支push权限

    1. 管理员身份登录GitHub,找到项目2. Settings-->Branches-->Protected branches--->Choose a branch... ,选择需 ...

  5. go笔记(go中的方法调用)

    最近接触go语言  发现和java的方法调用有些类似但又有自己的注意点 go的包我理解为则是隔离的最小模块 先在src目录下创建main.go文件  package为main,然后在src下创建mod ...

  6. layer 点击yes后在回调函数里获取layer.open({})iframe里面元素

    参考:http://fly.layui.com/jie/19690/ yes: function(index, layero) { uid.value = $(layero).find('iframe ...

  7. jqGrid不支持IE8的解决办法

    参考:https://blog.csdn.net/tarataotao/article/details/10376657

  8. Spring mvc mybatis 查询结果缺少字段 解决方法

    参考:https://blog.csdn.net/xiaofeifei8421/article/details/43231815

  9. vscode git 提交数据到分支

        1.vscode菜单--终端--新建终端   git config --global user.name "your name"   git config --global ...

  10. mysql安装到最后一步无响应的问题超简单最有效解决

    mysql安装到最后一步无响应的问题超简单最有效解决 无论你是安装过还是没安装过,通过此方法都可以解决.之前我的机器和服务器就是都到最后一步卡住,上网搜索方法都无果.后自己尝试了很多次,亲测64位机和 ...