Cod sursa(job #59606)
Utilizator | Data | 9 mai 2007 20:28:01 | |
---|---|---|---|
Problema | Frac | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.43 kb |
#include<fstream>
using namespace std;
short n,p,c=1,z;
int main()
{
ifstream fin("frac.in");
ofstream fout("frac.out");
int i,a,b;
fin>>n>>p;
for(i = 2;;i++)
{
a = n;
b = i;
while(b != a)
{
if(a > b)
a=a-b;
else
b=b-a;
}
if(a == 1)
{
c++;
z = i;
if(c == p)
{fout<<z;
return 0;
}
}
}
fin.close();
fout.close();
return 0;
}