1046 A^B Mod C
2016-04-03 00:14
417 查看
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
基准时间限制: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
-------------- 快速幂 */ import java.util.Scanner; public class Main1 { static long PowerMod(long a,long b,long c){ long ans=1; a%=c; while(b>0){ if((b&1)==1) ans=(ans*a)%c; a=(a*a)%c; b>>=1; } return ans; } public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); while(sc.hasNext()){ long a=sc.nextLong(); long b=sc.nextLong(); long c=sc.nextLong(); System.out.println(PowerMod(a,b,c)); } sc.close(); } }
相关文章推荐
- 平面公式,射线公式学习总结
- PHP禁止按照路径访问
- 191. Number of 1 Bits | Java最短代码实现
- 贪婪法——————贪心算法
- 对对象包装类ObjectInputStream/ObjectOutputStream的应用
- 用UDP编写网络聊天程序
- 1019 逆序数
- ArrayList和HashSet对的比较及HasCode分析
- 输出随机认证码图片
- 1012 最小公倍数LCM
- CTF——ASCII码而已
- 13.11编程练习
- 数组与Object的关系及其反射类型
- 数组的反射
- 1011 最大公约数GCD
- 1006 最长公共子序列Lcs
- 网络精灵系统
- BZOJ 4012 HNOI 2015 开店 动态点分治
- CTF——图片里的英语
- 【C++ Primer plus】【第八章】函数探幽