Cod sursa(job #1856679)

Utilizator gavrisraulRaul Gavris gavrisraul Data 25 ianuarie 2017 12:06:14
Problema Factorial Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p;
int nrdezero(int nr){
    int sum=0;
    while(nr){
        sum+=nr/5;
        nr/=5;
    }
    return sum;
}
int cautare(int st,int dr){
    st=0;dr=1<<30;
    int mij;
    while(st<=dr){
        mij=(st+dr)/2;
        if(nrdezero(mij)>=p)dr=mij-1;
        else st=mij+1;
    }
    if(nrdezero(mij)==p)return mij;
    return -1;
}
int main(){
    int first=0,last=1<<30;
    fin>>p;
    fout<<cautare(first,last);
    return 0;
}