Pagini recente » Cod sursa (job #699255) | Cod sursa (job #1638034) | Cod sursa (job #2301574) | Cod sursa (job #3000641) | Cod sursa (job #2587507)
#include <iostream>
#include <fstream>
#define nmax 10000005
using namespace std;
ifstream f("frac.in");
ofstream g ("frac.out");
bool v[nmax];
int b[nmax],k;
void ciur()
{
for(int i=2;i<=nmax-5;i++)
if(v[i]!=1)
for(int j=2*i;j<=nmax;j+=i)
v[j]=1;
for(int i=2;i<=nmax;i++)
if(v[i]==0)
b[++k]=i;
}
void div(int x)
{
for(int i=1;b[i]<=x and i<=k;i++)
if(x%b[i]==0)
v[b[i]]=1;
}
int main()
{
long long n,p;
f>>n>>p;
ciur();
div(n);
int i;
for(i=1;i<=nmax and p>0;i++)
if(v[i]==0)
p--;
g<<i-1;
return 0;
}