Pagini recente » Cod sursa (job #2276033) | Cod sursa (job #2962018) | Cod sursa (job #1335524) | Cod sursa (job #1405857) | Cod sursa (job #3194494)
#include <bits/stdc++.h>
using namespace std;
unsigned long long k=3, p, n;
vector <unsigned long long> divs;
ifstream in("frac.in");
ofstream out("frac.out");
bool check(unsigned long long nr)
{
for(int i=0;i<divs.size() && divs[i]<=nr;i++) if(nr%divs[i]==0) return 0;
return 1;
}
int main()
{
in>>n>>p;
if(n%2==0)
{
divs.push_back(2);
while(n%2==0) n/=2;
}
while(k<=n)
{
if(n%k==0)
{
divs.push_back(k);
while(n%k==0) n/=k;
}
}
for(int j=0,k=1;j<=p;)
{
if(j==p)
{
out<<k-1<<" ";
return 0;
}
if(check(k)) j++;
k++;
}
return 0;
}