A^B mod C
来源:互联网 发布:linux目录结构图 编辑:程序博客网 时间:2024/05/01 08:02
Problem Description
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<=1000000000).
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 42 10 1000 Sample Output
124#include<stdio.h>__int64 power(__int64 a,__int64 b,__int64 c){__int64 ans=1;while(b){if(b&1) //当b为奇数时{ans=(ans*a)%c; // a的99次方的等于a的49次方的平方,还要再乘以ab--;}b/=2; //二分a=a*a%c; // a的98次方的等于a的49次方的平方}return ans;}int main(){long a,b,c;while(scanf("%ld%ld%ld",&a,&b,&c)!=EOF){printf("%ld\n", power(a,b,c));}return 0;}
采用了二分法快速幂
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<=1000000000).
There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space.
For each testcase, output an integer, denotes the result of A^B mod C.
- A^B mod C
- A^B mod C
- A^B mod C
- BIT1044 A^B mod C
- 1046 A^B Mod C
- 1046 A^B Mod C
- 求a^b mod c
- 1046 A^B Mod C
- 1046 A^B Mod C
- Super A^B mod C
- 1046 A^B Mod C
- (A^B mod C)|(a^(n!) mod c)
- 模取幂运算 (a^b mod c)
- 【收藏】A^B mod C代码
- FZU 1752 A^B mod C
- A^B mod C的分治思想
- A^B mod C代码实现!
- 更高效率的a^b mod c
- Titan代碼行數
- Jquery读取xml并实现省市级联
- ++,--运算符及其副作用
- 经典嵌入式面试题目
- 英语笔记:写作:Free admissionsto museums
- A^B mod C
- javaBean Getter与Setter方法的内省调用
- word2010每次打开都弹出配置框解决方法
- java优化占用内存的方法
- 【MATLAB】画出一个基本图形框架,然后每次在这张基本图上做一个更新。
- php设计模式实例详解(综合)
- 单调队列
- bzoj3223==tyvj1729 文艺平衡树
- 怎么样判断IP地址是哪类地址?