Cod sursa(job #2495920)

Utilizator pro119Manea Dumitru pro119 Data 19 noiembrie 2019 23:29:03
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll p;
int face(int x){
    int sum=0,j=5;
    while(j<=x){
        sum+=(x/j);
        j*=5;
    }
    return sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ifstream cin("fact.in");
    ofstream cout("fact.out");
    cin>>p;
    ll l=1,r=10e7;
    bool aux=0;
    while(l<=r){
        ll mid=l+(r-l)/2;
        ll temp=fact(mid);
        ll temp2=fact(mid-1);
        if (temp==p && temp2<p) {
                cout<<mid;
                aux=1;
                break;
        }
        else if (temp<p) l=mid+1;
        else r=mid-1;
    }
    if(!aux) cout<<-1;
    return 0;
}