P5104 红包发红包(概率+飞马小定理求分数逆元)
题目描述:
思路:
AC代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 10000005; const int inf = 0x3f3f3f3f; const ll mod = 1000000007; ll qpow(ll a, ll n, ll p) { ll res = 1; while (n) { if (n & 1) { res = (res * a) % p; } a = (a * a) % p; n >>= 1; } return res; } int main() { ll w, n, k; scanf("%lld%lld%lld", &w, &n, &k); printf("%lld", w * qpow(qpow(2, k, mod), mod - 2, mod) % mod); return 0; }