You are viewing a single comment's thread. Return to all comments →
Here's my solution in JAVA:
static int solve(int n, int m) { if (n == 1) return m%(1000000007); BigInteger result = new BigInteger(""+m); result = result.multiply(new BigInteger(""+(m-1))); BigInteger newBig = new BigInteger(""+(m-2)); newBig = newBig.modPow(new BigInteger(""+(n-2)),new BigInteger("1000000007")); result = result.multiply(newBig); return result.mod(new BigInteger("1000000007")).intValue(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Anti-Palindromic Strings
You are viewing a single comment's thread. Return to all comments →
Here's my solution in JAVA: