Cod sursa(job #355934)

Utilizator Hori93Simon Horatiu Hori93 Data 12 octombrie 2009 19:26:21
Problema Frac Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#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;
  
}