Cod sursa(job #663748)

Utilizator dutzulBodnariuc Dan Alexandru dutzul Data 18 ianuarie 2012 21:42:32
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#define l 100000000
using namespace std;
ifstream f ( "fact.in" );
ofstream g ( "fact.out" );
int p,ok,poz,i,I;

int OK ( int val )
{
    int X=val,cif=0,C;
    for ( C=5; C<=val; C*=5 )
        cif+=X/C;

    return cif;
}
int caut ( int PE )
{
    int step=1,p=0;
    for ( ; step<=l; step*=2 );

    for ( ; step; step/=2 )
        if ( OK ( p+step ) <= PE ) p+=step;
    return p;
}

int main()
{   f>> p;
    poz=caut ( p -1 );

    for ( i=poz; i<=poz+5&&ok==0; i++ )
    {
        I=i;
        if ( OK ( I ) ==p ) {
            g<<I;
            ok=1;
            continue;
        }
    }
    if ( ok==0 ) g<<-1;
    f.close();
    g.close();
    return 0;
}