Cod sursa(job #918709)

Utilizator pauldinudinu paul pauldinu Data 19 martie 2013 08:09:04
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");
int zero(int x)
{
    int r=0;
    while(x>=5)
    {
        r=r+x/5;
        x=x/5;
    }
    return r;
}
int cautare(int x)
{
    int i=0,pas=1<<30;
    while(pas!=0)
    {
        if(zero(i+pas)<x)
            i+=pas;
        pas/=2;
    }
    return i+1;
}
int main()
{
    int p,r;
    f>>p;
    r=cautare(p);
    if(p==0) g<<1;
    else if(zero(r)==p) g<<r;
    else g<<-1;
    return 0;
}