Cod sursa(job #1515976)

Utilizator RaresGabrielMircea Rares-Gabriel RaresGabriel Data 2 noiembrie 2015 16:02:20
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<iostream>
#include<fstream>
#include<climits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int zero(int m){
    int p=5,k=0;
    while(p<=m){
        k=k+m/p;
        p=p*5;
    }
    return k;
}

int main(){
    int i,j,m,p;
    bool ok;
    fin>>p;
    if(p==0)fout<<"1";
    i=1;j=INT_MAX;ok=false;
    while(i<=j&&!ok){
        m=(i+j)/2;
        if(zero(m)==p)ok=true;
        else if(zero(m)<p)i=m+1;
            else j=m-1;
    }
    if(ok){
        m=m-m%5;
        fout<<m<<" ";
    }
    else fout<<"-1";
    return 0;
}