Cod sursa(job #1485771)

Utilizator DavidCelJmekerPopescu David Ioan DavidCelJmeker Data 12 septembrie 2015 22:08:36
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <iostream>
using namespace std;

int zero(int ) ;

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

        mj=(st+dr)/2;
        if(zero(mj)>=p){
            last=mj;
            dr=mj-1;
        }
        else
            st=mj+1;
    }
    while(zero(last) == p && last != 0)
        --last;
    ++last;
    if(zero(last) != p || last == 0)
        last = -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;
}