有没有用费马定理+快速幂跑出来的,最后两个TLE了。
查看原帖
有没有用费马定理+快速幂跑出来的,最后两个TLE了。
513069
wild_pointer楼主2022/2/17 22:03
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int qp(int a,int k,int m)
{
	int res=1;
	while(k){
		if(k&1) res=(ll)res*a%m;
		k>>=1;
		a=(ll)a*a%m;
	}
	return res;
}
int main()
{
	int n,p;
	cin>>n>>p;
	for(int i=1;i<=n;i++){
		printf("%d\n",qp(i,p-2,p));
	}
	return 0;
}
2022/2/17 22:03
加载中...