Cod sursa(job #1901908)

Utilizator Cristi_ChiraChira Cristian Cristi_Chira Data 4 martie 2017 11:56:31
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int nr0(int x)
{
    int p=5, rez=0;
   while(p<x)
   {
       rez+=x/p;
       p*=5;
   }
   return rez;
}
int cb(long long x)
{
    long long dr=INT_MAX, st=0;
    long long mid;
    while(st<dr)
    {
        mid=(dr+st)/2;
        if(nr0(mid)>x)
        {
            dr=mid;
        }
        else
            st=mid+1;
    }
    return st;

}
int main()
{
    int n;
    fin>>n;
    if(nr0(cb(n)-5)!=n)
        fout<<-1;
    else
    fout<<cb(n)-5;
    return 0;
}