https://www.oitiku.com/simulate-contest/2/4
本人代码(根据Pollard-Rho改的)
#include<bits/stdc++.h>
#define lll __int128
#define fre(z) freopen(z".in","r",stdin),freopen(z".out","w",stdout)
using namespace std;
typedef long long ll;
typedef double db;
inline ll read(){
char ch=getchar();
long long x=0,f=1;
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
return x*f;
}
ll max_factor;
priority_queue<long long, vector<long long> >Q;
inline ll gcd(ll a,ll b) {
if(b==0) return a;
return gcd(b,a%b);
}
inline ll qp(ll a1,ll b,ll MOD) {
ll ans2=1;
while(b){
if(b&1)
ans2=(ans2*a1)%MOD;
a1=(a1*a1)%MOD;
b>>=1;
}
return ans2;
}
inline ll qp2(ll a1,ll b) {
ll ans2=1;
while(b){
if(b&1)
ans2=(ans2*a1);
a1=(a1*a1);
b>>=1;
}
return ans2;
}
inline bool mr(ll x,ll b) {
ll k=x-1;
while(k)
{
ll cur=qp(b,k,x);
if(cur!=1 && cur!=x-1)
return false;
if((k&1)==1 || cur==x-1)
return true;
k>>=1;
}
return true;
}
inline bool prime(ll x)
{
if(x==46856248255981ll || x<2)
return false;
if(x==2 || x==3 || x==7 || x==61 || x==24251)
return true;
return mr(x,2)&&mr(x,61);
}
inline ll f(ll x,ll c,ll n)
{
return (lll)(x*x+c)%n;
}
inline ll PR(ll x)
{
ll s=0,t=0,c=1ll*rand()%(x-1)+1;
int stp=0,goal=1;
ll val=1;
for(goal=1;;goal<<=1,s=t,val=1)
{
for(stp=1;stp<=goal;++stp)
{
t=f(t,c,x);
val=(lll)val*abs(t-s)%x;
if((stp%127)==0)
{
ll d=gcd(val,x);
if(d>1)
return d;
}
}
ll d=gcd(val,x);
if(d>1)
return d;
}
}
inline void fac(ll x)
{
if(x<=max_factor || x<2)
return;
if(prime(x))
{
max_factor=max_factor>x?max_factor:x;
return;
}
ll p=x;
while(p>=x)
p=PR(x);
while((x%p)==0)
x/=p;
fac(x),fac(p);
}
int main()
{
srand((unsigned)time(NULL));
ll n=read(),k=read();
int i=0,j=0;
while(i<k&&n^1) {
max_factor=0,j=0;
fac(n);
while(!(n%max_factor)) n/=max_factor,j++;
Q.push(qp2(max_factor,j));
i++;
}
while(!Q.empty()) printf("%lld ",Q.top()),Q.pop();
while(i<k) printf("1 "),i++;
return 0;
}
结果得了90分(排名第43) 感觉PR是不是麻烦了?