Pagini recente » Cod sursa (job #2262237) | Cod sursa (job #2058291) | Cod sursa (job #722748) | Cod sursa (job #337319) | Cod sursa (job #355934)
Cod sursa(job #355934)
#include<fstream>
using namespace std;
ofstream fout("frac.out");
ifstream fin("frac.in");
long long n, p;
int Prim(long x,long y)
{
while ( x != y )
{
if ( x > y )
x = x - y ;
else y -= x;
}
if ( x == 1 )
return 1;
return 0;
}
void Op()
{
long long nr, ct = 0 ; // contor
fin >> n ;
fin >> p;
nr = 1 ;
while ( ct < p )
{
nr++;
if ( n%2 == 0 || nr % 2 == 0) ;
else
if ( Prim (n , nr) )
ct++ ;
}
fout<<nr;
fin.close();
fout.close();
}
int main()
{
Op();
return 0;
}