Cod sursa(job #912147)

Utilizator PetrutiuPaulPetrutiu Paul Gabriel PetrutiuPaul Data 12 martie 2013 09:36:42
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include<fstream>
#include<iostream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("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;
    fin>>p;
    x=cautare(p)+1;
    if(zero(x)==p)
    {
        fout<<x;
        return 0;
    }
    fout<<"-1";
    return 0;
}