Cod sursa(job #911351)

Utilizator apopeid13Apopeid Alejandro apopeid13 Data 11 martie 2013 16:04:31
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>
using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
int zero(int n)
{
    int rez=0,p=5;
    while(p<=n)
    {
        rez+=n/p;
        n/=p;
    }
    return rez;
}
int cautare(int p)
{
    int i=0,pas=1<<29;
    while(pas!=0)
    {
        if(zero(i+pas)<p)
            i+=pas;
        pas/=2;
    }
    return i;
}
int main()
{
    int p,x;
    in>>p;
    x=cautare(p)+1;
    if(zero(x)==p)
    {
        out<<x;
        return 0;
    }
    out<<"-1";
    return 0;
}