64分求助!!最后两个TLE!
查看原帖
64分求助!!最后两个TLE!
597555
hzb1121楼主2022/7/7 16:21

费马小定理都过不了?

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll qpow(ll a,ll b,ll p)
{
	ll ans=1;
	while(b)
	{
		if(b%2==1)
		{
			ans%=p;
			a%=p;
			ans=ans*a%p;
		}
		a%=p;
		a=a*a%p;
		b=b>>1;
	}
	return ans%p;
}
int main()
{
	ll a,p;
	while(~scanf("%lld %lld",&a,&p))
	{
		for(int i=1;i<=a;i++)
		{
			printf("%lld\n",qpow(i,p-2,p));
		}
	}
	return 0;
}
2022/7/7 16:21
加载中...