Cod sursa(job #1129077)

Utilizator bogdanpaunFMI Paun Bogdan Gabriel bogdanpaun Data 27 februarie 2014 20:00:08
Problema GFact Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <fstream>

#define x first
#define y second
using namespace std;
long int n,q, COUNT,p,a;
pair<int,int> V[100005];

 long long LEFT , RIGHT, MIDDLE;
bool VERIF(){
    for( register long long i=1;i <= COUNT; ++i ){
        p = V[i].x , a=0;
        while( p <= MIDDLE && a <= V[i].y )
            a+=MIDDLE/p , p*=V[i].x;
        if( a < V[i].y ) return 0;
    }
    return 1;
}

int main()
{
    ifstream f("gfact.in");
    f>>n>>q;  f.close();
    int AUX=n;

    for(  register int i=2; i <= n/i ; ++i )
        if( !(AUX%i)  ){
            V[ ++COUNT ].x=i;
            while( !(AUX%i) )   V[ COUNT ].y+=q, AUX /= i;
        }
    if( AUX ) V[ ++COUNT ].x=AUX,V[COUNT].y=q;

     LEFT=1 , RIGHT=1LL*n*q ;

    while( LEFT <= RIGHT ){
        MIDDLE = ( LEFT + RIGHT ) >>1;
        if( VERIF() )
            RIGHT = MIDDLE -1;
        else
            LEFT = MIDDLE +1;
    }
    ofstream g("gfact.out");
    g<<LEFT;
    g.close();
    return 0;
}