Topic Portal
1 /*2 Test instructions: To find the number of full permutations of the bubble sort scan K-Times3 Mathematics: Here is the concept of an anti-sequence table, BJ is represented on the left of J, but is greater than the number of J. Not much to say, I also look at the online problem-solving report. 4 Detailed Explanation:http://blog.csdn.net/cscj2010/article/details/78209065 */6#include <cstdio>7#include <algorithm>8#include <cstring>9#include <cmath>Ten using namespacestd; One AtypedefLong Longll; - Const intMAXN = 1e6 +Ten; - Const intINF =0x3f3f3f3f; the Const intMOD =20100713; - ll FACT[MAXN]; - - voidSolvevoid) { +fact[0] = fact[1] =1; - for(intI=2; i<=1000000; ++i) { +Fact[i] = fact[i-1] * I%MOD; A } at } - - ll Pow_mod (ll X, ll N) { -LL ret =1; - while(n) { - if(N &1) ret = ret * x%MOD; inx = x * x%MOD; -N >>=1; to } + returnret; - } the * intMainvoid) {//POJ 3761 Bubble Sort $ solve ();Panax Notoginseng intT scanf ("%d", &T); - while(t--) { thell N, K; scanf ("%i64d%i64d", &n, &k); +printf ("%i64d\n", (Pow_mod (k +1, N-k)-Pow_mod (k, n-k) + MoD)% mod * Fact[k]%MOD); A } the + return 0; -}
Quick power modulo POJ 3761 bubble sort