Cod sursa(job #1423726)

Utilizator zacuscaAlex Iordache zacusca Data 22 aprilie 2015 14:20:16
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include<fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int p,n,sol;
int nr0(int x)
{
    int cnt=0;
    int p=5;
    while(p<=x)
    {
        cnt+=x/p;
        p*=5;
    }
    return cnt;
}
int main()
{
    in>>p;
    if(!p)out<<"1\n";
    int st=1,dr=10*p;
    bool found =0;
    while(st<dr&&!found)
    {
        int m=st+(dr-st)/2;
        int aux=nr0(m);
        if(aux==p)
        {
            sol=m;
            found =1;
        }
        else if(aux>p)
            dr=m-1;
        else st=m+1;
    }
    while(nr0(sol)==p)sol--;
    out<<sol+1<<'\n';
    out.close();
    return 0;
}