# my ability is poor!

#include <iostream>
#include <cmath>
#include <queue>

using namespace std;
#define  M 10000

int prime[M];
bool is[M];
int factor[20];

struct E
{
int a,b;
E(int a=0,int b=0){this->a=a;this->b=b;};
};
void creatprime()
{
memset(is,0,sizeof(is));
int k=0;
prime[k++]=2;
for(int i=4;i<M;i+=2)
is[i]= true;
for(int i=3;i<M;i+=2)
{
if(!is[i])
{
prime[k++] = i;
for(int j=i+i;j<M;j+=i)
is[j] = true;
}
}
return ;
}

void creatfactor(int n)
{
memset(factor,0,sizeof(factor));
int k=0;int m=n;
for(int i=0;prime[i]*prime[i]<=m && n!=1;i++)
if(n%prime[i]==0)
{
factor[k++] = prime[i];
while(n%prime[i]==0)
n/=prime[i];
}
if(n!=1) factor[k++] = n;
return ;
}
int howmany(int n)
{
queue<E> G;
for(int i=0;i<20&&factor[i]!=0;i++)
G.push(E(factor[i],factor[i]));
int sum = 0;
while(!G.empty())
{
E ele = G.front();G.pop();
sum += n/ele.a;
for(int i=0;i<20&&factor[i]!=0;i++)
{
if(factor[i]>ele.b)
{
int temp = ele.a;
temp *= -factor[i];
if(n/abs(temp)!=0)
{
G.push(E(temp,factor[i]));
}
}
}
}
return sum;

}
bool hasfactor(int n)
{
for(int i=0;i<20&&factor[i]!=0;i++)
if(n%factor[i]==0)return true;
return false;
}
int main()
{
int k,m;

creatprime();

while(scanf("%d%d",&k,&m)!=EOF)
{
if(m==1){puts("1");continue;}
if(k==1){printf("%d\n",m);continue;}
creatfactor(k);

int temp = howmany(m);
temp = m-temp;
for(int i=m+1;;i++)
{
if(!hasfactor(i))temp++;
if(temp==m) {printf("%d\n",i);break;}
}
}
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：my ability is poor! 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)