牛客小白月赛28 A
牛牛和牛可乐的赌约
https://ac.nowcoder.com/acm/contest/7412/A
分析
我们可以求出单次抛出 的概率为
,所以赢的概率为
,那么输掉的概率为
,快速幂计算,时间复杂度为
。
代码
#include<bits/stdc++.h>
using namespace std;
int read() {
int x = 0,f = 0;char ch = getchar();
while(!isdigit(ch)) {if(ch == '-') f = 1;ch = getchar();}
while(isdigit(ch)) {x = x*10 + ch - '0';ch = getchar();}
return f?-x:x;
}
const int N = 1e5+100,p = 1e9 + 7;
#define LL long long
LL qpow(LL a,LL b) {
LL x = 1;for(;b;b>>=1,a = a*a % p) {
if(b&1) x = x * a % p;
}
return x;
}
signed main() {
int T = read();
while(T--) {
LL n = read(),m = read();
printf("%lld\n",(p+1-qpow(qpow(n,m),p-2))%p);
}
}比赛题解 文章被收录于专栏
近期比赛的题解应该有吧。。。


查看11道真题和解析