牛客小白賽9A(求逆元)
阿新 • • 發佈:2018-12-22
思路:
就是求個逆元會求了,這題也就會做了。程式碼如下:
#include<cstdio> #define ll long long const ll mod=1e9+7; ll quick_pow(ll a,ll b) { ll ans=1; while(b) { if(b&1) { ans=ans*a%mod; } a=a*a%mod; b>>=1; } return ans; } int main() { int n; scanf("%d",&n); ll suma=1; ll sumb=1; while(n--) { ll a,b; scanf("%lld%lld",&a,&b); a=b-a; suma*=a; sumb*=b; suma%=mod; sumb%=mod; } printf("%lld\n",(((sumb-suma+mod)%mod)*(quick_pow(sumb,mod-2)))%mod); return 0; }