因为
于是逆推,x=φ(x)*(p1/(p1-1))…(pn/(pn-1))
搞出10^7以内的质数值,根据上面的式子不断的递归,直到φ(x)==1就找到了相应的x了。
但是测试数据和STD不太对,因为STD当φ(N)==1,不会筛2,,其实是可以晒的。
只要把返回写到后面去就行了。
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#define ll long long
using namespace std;
const int maxm=1e7+1;
ll prime[999999],cnt;
bool vis[11000000];
ll ans[maxm],tot;
void pre()
{
vis[1]=1;
for(int i=1;i<=maxm;i++)
{
if(!vis[i])
prime[++cnt]=i;
for(int j=1;j<=cnt&&i*prime[j]<=maxm;j++)
{
vis[prime[j]*i]=1;
if(i%prime[j]==0)
break;
}
}
}
ll mul(ll x,ll y,ll mod)
{
ll ans=0;
while(y)
{
if(y%(1ll*2)) ans=(ans+x%mod)%mod;
y/=(1ll*2);
x=(x%mod+x%mod)%mod;
}
return ans;
}
ll fast_pow(ll x,ll y,ll m)
{
ll ans=1;
x%=m;
while(y)
{
if(y%2)
ans=mul(ans, x, m);
y/=2;
x=mul(x, x, m);
}
return ans;
}
bool MR(ll n)
{
if(n == 2) return 1;
if(n < 2 || !(n & 1)) return 0;
ll m=n-1;
ll k=0;
while((k&1)==0)
{
k++;
m/=2;
}
for(int i=0; i<12; i++)
{
ll a=rand()%(n - 1)+1;
ll x=fast_pow(a, m, n);
ll y=0;
for(int j=0; j<k; j++)
{
y=mul(x,x,n);
if(y==1&&x!=1&&x!=n-1) return 0;
x = y;
}
if(y!=1) return 0;
}
return 1;
}
void dfs(ll x,ll y,ll z)
{
if(x+1>prime[cnt]&&MR(x+1))
ans[++tot]=(x+1)*y;
for(int i=z;i>=1;i--)
if(x%(prime[i]-1)==0)
{
ll t1=x/(prime[i]-1);
ll t2=y;
ll c=1;
while(t1%c==0)
{
t2*=prime[i];
dfs(t1/c,t2,i-1);
c*=prime[i];
}
}
if(x==1)
{
ans[++tot]=y;
return;
}
}
int main()
{
ll n,k;
scanf("%lld%lld",&n,&k);
pre();
dfs(n,1,cnt);
sort(ans+1,ans+tot+1);
for(int i=1;i<=k;i++)
printf("%lld ",ans[i]);
return 0;
}