Problem 1759 Super A^B mod C
Accept: 878 Submit: 2870 Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
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
Source
FZU 2009 Summer Training IV--Number Theory
题目链接:
参考博客:,本来在搞蛇精病的十进制快速幂的时候做的这个,结果超时了,后来测试发现十进制快速幂还没二进制快……是我太天真了……于是膜一下正确解法,主要利用了这个欧拉定理的扩展公式,当然最重要的是求出一个数的欧拉函数值$phi(x)$,这个可以用埃式筛的思想求得。
代码:
#include#include #include #include #include #include #include #include #include #include #include #include #include #include #include