Cod sursa(job #1902790)

Utilizator Cristi_ChiraChira Cristian Cristi_Chira Data 4 martie 2017 19:50:40
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <iostream>
#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;
   }
   if(!rez)
    return 1;
   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(n==0)
    {fout<<1;
     return 0;}
    if(nr0(cb(n)-5)!=n)
        fout<<-1;
    else
    fout<<cb(n)-5;
    return 0;
}