Cod sursa(job #2281361)

Utilizator pasoi_stefanPasoi Stefan pasoi_stefan Data 12 noiembrie 2018 08:46:27
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
int ans,step,i,p;
int rez(int x){
    int r=0;
    while(x){
        r+=x/5;
        x/=5;
    }
    return r;
}
int main(){
    cin>>p;
    if(p==0){
        cout<<1;
        return 0;
    }
    i=0; step=1;
    while(step<=5*p) step<<=1;
    while(step){
        if(rez(i+step)<=p)
            i+=step;
        step>>=1;
    }
    if(rez(i+step)!=p) cout<<-1;
    else cout<<(i-4);
}