Cod sursa(job #1485728)

Utilizator DavidCelJmekerPopescu David Ioan DavidCelJmeker Data 12 septembrie 2015 19:57:40
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <iostream>
using namespace std;

int zero(int ) ;

int main()
    ifstream("fact.in") ;
    ofstream("fact.out") ;
    int st=0 , dr=5*p , p , mj, last;
    in>>p;
    last=-1;
    while(st<=dr){

        mj=(st+dr)/2;
        if(zero(mj)<=p){
            last=mj;
            st=mj+1;
        }
        else
            dr=mj-1;
    }
     out<<last;



    return 0;

}
int zero(int x)
{
    int nrzr=0;
    int k=5;
    while(x>=k)
    {
        nrzr=nrzr+x/k;
        k=k*5;
    }
    return nrzr;
}