Pagini recente » Cod sursa (job #1098056) | Cod sursa (job #506492) | Cod sursa (job #2103010) | Cod sursa (job #2276670) | Cod sursa (job #2476887)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("frac.in");
ofstream cout("frac.out");
vector<int> v;
int x, p;
void rez()
{
long long t = 1, nr = 0;
for(int i = 1 ; i <= 61 ; i ++)
t = t << 1;
for(long long j = 1 ; j <= t ; j++ )
{
bool ok = 1;
for(int i = 0 ; i < v.size() && ok ; i++)
if(j % v[i] == 0)
ok = 0;
if(ok)
{
//cout << j << '\n';
nr++;
}
if(p == nr)
{
cout << j ;
return ;
}
}
}
int main()
{
cin >> x >> p;
if(!(x & 1))
{
v.push_back(2);
while( !(x & 1) )
x >>= 1;
}
int d = 3;
while( d* d <= x)
{
if(!(x % d))
{
v.push_back(d);
while(!(x % d))
x /= d;
}
d += 2;
}
if(x > 1)
v.push_back(x);
rez();
return 0;
}