Cod sursa(job #1937943)

Utilizator TornerroRusu Marius Tornerro Data 24 martie 2017 14:21:10
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int nr0(int x)
{
    int p=5,s=0;
    while(p<=x)
    {
        s=s+x/p;
        p*=5;
    }
    return s;
}

int main()
{
    int i,p,a=1,b=INT_MAX-1,x=0;
    fin>>p;
    if(p==0)fout<<1;
    else
    {
        while(x!=p)
        {
            i=(a+b)/2;
            x=nr0(i);
            if(x>p)a=i+1;
            else if(x<p)b=i-1;
        }
        i=i-i%5;
        fout<<i;
    }
    return 0;
}