import java.util.Scanner; public class 越狱 { /** * 解题思路大致如下: * 首先思考所有方案数:mn=m*m(n-1) * 所有不发生越狱的方案数:m*(m-1)(n-1)种 * 所以发生越狱的方案数:m*m(n-1)-m*(m-1)(n-1)=m*(m(n-1)-(m-1)(n-1)) * 分别对m(n-1)和(m-1)(n-1)快速幂即可 */ static long mod = 100003; public static long pow(long x, long y) { long ans = 1; long d = x%mod; while(y>0){ if(y%2==1) { ans = (ans * d) % mod; } y=y/2; d=(d*d)%mod; } return ans; } public static void main(String[] args) { Scanner in = new Scanner(System.in); long m = in.nextLong(); long n = in.nextLong(); long tot = pow(m,n); tot -= m*pow(m-1,n-1)%mod; if(tot<0) tot+=mod; System.out.println(tot); } }
0.0分
1 人评分
点我有惊喜!你懂得!浏览:1068 |
C语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:720 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:519 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:1222 |
WU-输入输出格式练习 (C++代码)浏览:1078 |
DNA (C语言描述,数据结构)浏览:851 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:604 |
Tom数 (C语言代码)浏览:725 |
字符串的输入输出处理 (C语言代码)浏览:985 |
钟神赛车 (C语言代码)浏览:590 |