Cod sursa(job #1129084)

Utilizator bogdanpaunFMI Paun Bogdan Gabriel bogdanpaun Data 27 februarie 2014 20:04:28
Problema GFact Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>

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

 long long LEFT , RIGHT, MIDDLE,a,p;
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!=0 ) {V[ ++COUNT ].x=AUX;V[COUNT].y=q;}

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

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