Pagini recente » Cod sursa (job #1005284) | Cod sursa (job #368307) | Istoria paginii runda/lanitam_urtimud/clasament | Cod sursa (job #392147) | Cod sursa (job #716642)
Cod sursa(job #716642)
#include<iostream>
#include<fstream>
using namespace std;
int n,p,i,j,v[1000],ok;
ifstream f("frac.in");
ofstream g("frac.out");
int cmmdc(int x,int y,int ok)
{while(x!=y)
if(x>y)
x=x-y;
else y=y-x;
if(x!=1&&y!=1)
ok=0;;
return ok;}
int main()
{f>>n>>p;
i=0;
j=0;
while(i<=p)
{j++;
if(cmmdc(j,n,1)==1)
{i++;
v[i]=j;
}
}
cout<<v[p];
f.close();
g.close();
return 0;
}