Cod sursa(job #1901871)

Utilizator sergiudnyTritean Sergiu sergiudny Data 4 martie 2017 11:40:36
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int zero(ull x){
    ull p=5,rez=0;
    while(p<=x){
        rez+=(x/p);
        p*=5;
    }
    if(!x) return 1;
    return rez;
}
int main()
{
    int p;
    fin>>p;
    if(!p){
        fout<<1;
        return 0;
    }

    ll st=0,dr=INT_MAX;
    while(dr>st){
        ll mij=(dr+st)/2;
        if(zero(mij)<p) st=mij+1;
        else dr=mij;
    }
    if(zero(st)!=p) fout<<-1;
    else fout<<st;
    return 0;
}