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语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:1514 |
P1002 (C语言代码)浏览:970 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:464 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:664 |
核桃的数量 (C语言代码)浏览:668 |
1024题解浏览:806 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:1909 |
矩阵乘方 (C语言代码)浏览:1022 |
星期判断机 (C语言代码)浏览:859 |
矩形面积交 (C++代码)浏览:1127 |