Pagini recente » Monitorul de evaluare | Victorie | Monitorul de evaluare | Istoria paginii utilizator/deneo | Cod sursa (job #2074089)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("gfact.in");
ofstream g("gfact.out");
int v[200], d[300], nd;
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 = 0; i < nd; i++ ) {
if ( putere(n, v[i]) < d[i] ) {
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()
{
int n, fact;
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;
}