Cod sursa(job #2281355)

Utilizator pasoi_stefanPasoi Stefan pasoi_stefan Data 12 noiembrie 2018 08:39:35
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.49 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
typedef unsigned long long ull;
ull ans,step,i,p;
ull rez(ull x){
    ull 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=(1LL<<63);
    while(step){
        if(rez(i+step)<=p)
            i+=step;
        step>>=1;
    }
    cout<<(i-4);
}