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 人评分
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:946 |
川哥的吩咐 (C++代码)浏览:1016 |
【计算两点间的距离】 (C语言代码)浏览:884 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:572 |
字符串比较 (C语言代码)答案错误????浏览:597 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:760 |
WU-整除问题 (C++代码)浏览:612 |
蛇行矩阵 (C语言代码)浏览:536 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:633 |
C二级辅导-阶乘数列 (C语言代码)浏览:521 |