Cod sursa(job #2476887)

Utilizator ArkhamKnightyMarco Vraja ArkhamKnighty Data 19 octombrie 2019 12:08:34
Problema Frac Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#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;
}