Cod sursa(job #2150884)

Utilizator iandavidroIan David Bocioaca iandavidro Data 3 martie 2018 21:00:43
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<bits/stdc++.h>
#define int long long
using namespace std;

int p,n;
bool u;

int check(int n) {
    int s=0;
    for (int i=5; i<=n; i*=5) s+=n/i;
    return s;
}

int32_t main() {
    ifstream cin("fact.in");
    ofstream cout("fact.out");
    cin>>p;
    int st=0, dr=1e9;

    while (st<=dr) {
        int mid=(st+dr)/2;
        int a=check(mid);
        if (a==p) u=1;
        if (a>=p) dr=mid-1;
        else {
            st=mid+1;
        }
    }
    if (p==0) cout<<"1";
    else
    if (u) cout<<dr+1;
    else cout<<"-1";



    return 0;
}