Cod sursa(job #1708077)

Utilizator MoleRatFuia Mihai MoleRat Data 26 mai 2016 15:40:38
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

const int pas=1<<30;
int zero(int n)
{
    int x=0;
    while(n>=5)
    {
        x+=n/5;
        n/=5;
    }
    return x;
}

int main()
{
    int n,p,i,y;
    fin>>p;
    y=pas;
    i=0;
    while(y!=0)
    {
        if(zero(i+y)<p)
            i+=y;
        y/=2;
    }
    i++;
    if(zero(i)==p)
        fout<<i;
    else
        fout<<-1;
        return 0;
}