Codeforces 711E ZS and The Birthday Paradox 数学

时间:2023-03-10 08:25:43
Codeforces 711E ZS and The Birthday Paradox 数学

ZS and The Birthday Paradox

感觉里面有好多技巧。。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e6 + ;
const double eps = 1e-; LL n, k; LL power(LL a, LL b) {
b %= mod - ;
LL ans = ;
while(b) {
if(b & ) ans = ans * a % mod;
a = a * a % mod; b >>= ;
}
return ans;
} int main() {
scanf("%lld%lld", &n, &k);
if(n < && (1ll << n) < k) {
puts("1 1");
} else {
LL num = ;
for(LL i = k - ; i; i /= ) num += i / ;
LL A = power(, n), B = ;
for(LL i = ; i < k; i++) {
B = B * (A - i) % mod;
if(A == i) break;
}
LL inv = power(power(, num), mod - );
B = B * inv % mod;
A = power(A, k - ) * inv % mod;
printf("%lld %lld\n", (A - B + mod) % mod, A);
}
return ;
} /*
*/