Cod sursa(job #1024082)

Utilizator leontinLeontin leontin Data 8 noiembrie 2013 10:34:10
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>



using namespace std;
 ifstream f("fact.in");
ofstream g("fact.out");
int binary(long st,long dr, long p)
{
    while(st<=dr)
    {
        long med=(dr+st)/2;
        long x,y;
        x=0;
        y=5;
        while(y<=med)
        {
            x=x+med/y;
            y=y*5;
        }
        if(x==p && med%5==0)
        {
            return med;
        }
        else
        {
            if(x<p)
                st=med+1;
            else
                dr=med-1;
        }
    }
    return -1;
}

int main()
{
    int p;
    f>>p;
    if(p==0)
g<<1<<endl;
    else
        g<<binary(1,100000000,p);

    return 0;
}