Cod sursa(job #2074134)

Utilizator Andrei_RAndrei Roceanu Andrei_R Data 24 noiembrie 2017 09:31:07
Problema GFact Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("gfact.in");
ofstream g("gfact.out");

int v[2000], d[3000], nd, fact, n;

long long putere ( long long n, int al) {
    long long s = 0;
    while ( n >= al ) {
        s += (n/=al);
    }
    return s;
}

bool sepoate( long long n ) {
    for ( int i = 1; i <= nd; i++ ) {
        if ( putere(n, v[i]) < d[i] * fact ) {
            return false;
        }
    }
    return true;
}
long long cb() {
    long long r = 0, pas;
    pas = 1LL << 60;
    while ( pas != 0 ) {
        if ( !sepoate(r+pas) )
            r += pas;
        pas /= 2;
    }
    return r+1;
}

long long r;

int main()
{
    f >> n >> fact;
    int hb = 2;
    nd = 0;
    while( hb * hb <= n ) {
        if( n % hb == 0 ) {
            nd++;
            v[nd] = hb;
            while( n % hb == 0 ) {
                n /= hb;
                d[nd]++;
            }
        }
        hb++;
    }
    if( n != 1 ) {
        nd++;
        d[nd] = 1;
        v[nd] = n;
    }
    r = cb();
    g << r;
    f.close();
    g.close();
    return 0;
}