Cod sursa(job #2195589)

Utilizator RadutaLaviniaElenaRaduta Lavinia Elena RadutaLaviniaElena Data 16 aprilie 2018 19:51:27
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int zero(int x)
{
    int p=1,k=0,i;
    for(i=1;i<=x;i++)p*=i;
    while(p%10 == 0){k++; p=p/10;}
    return k;
}

int cb(int p)
{
    int st=1,dr=5*p;
    while(st<=dr)
    {
        int m=(st+dr)/2,z; z=zero(m);
        if(z == p)return m;
        else
            if(z < p)st=m+1;
            else
                dr=m-1;
    }
    return -1;
}

int main()
{
    int p; fin>>p;
    if(p==0)fout<<1;
    else
        fout<<cb(p);
    return 0;
}