Cod sursa(job #716642)
Utilizator | Data | 19 martie 2012 08:36:46 | |
---|---|---|---|
Problema | Frac | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.41 kb |
#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;
}