牛客小白赛9A(求逆元)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39562952/article/details/84198776

思路:

就是求个逆元会求了,这题也就会做了。代码如下:

#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;
}

猜你喜欢

转载自blog.csdn.net/qq_39562952/article/details/84198776