Cod sursa(job #1317221)

Utilizator bogdanmarin69Bogdan Marin bogdanmarin69 Data 14 ianuarie 2015 18:45:44
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;
int nz(int x){
    int rez=0,f=5;
    while(x/f>0){
        rez+=x/f;
        f=f*5;
    }
    return rez;
}
int main()
{
    int p,i,st=1,dr;
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    fin>>p;
    dr=p*5;
    while(st<=dr){
        int mij=(st+dr)/2;
        if(nz(mij)<p)
            st=mij+1;
        else
            dr=mij-1;
    }
    if(nz(st)==p)
        fout<<st;
    else
        fout<<"-1";
    return 0;

}