Cod sursa(job #1823096)

Utilizator Liviu_Ionut_MoantaMoanta Ionut Liviu Liviu_Ionut_Moanta Data 5 decembrie 2016 22:08:22
Problema Factorial Scor 90
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");
long long p,mid,st,dr;
long long expo(long long p){
    long long x=5;
    long long sol=0;
    if(x>p){
        return 0;
    }
    while(x<=p){
        sol+=p/x;
        x*=5;
    }
    return sol;
}
int main(){
    fin>>p;
    st=1;
    dr=2000000000LL;
    while(st<=dr){
        mid=(st+dr)/2;
        if(expo(mid)>=p){
            dr=mid-1;
        }
        else{
            st=mid+1;
        }
    }
    fout<<st;
    return 0;
}