Cod sursa(job #1822342)

Utilizator Daniel1999Daniel-Nicolae Paraschiv Daniel1999 Data 4 decembrie 2016 19:29:23
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>
using namespace std;
long long l,r,p,m,b;
int n(int a)
{
    int i=5,t=0,k=0;
    while(i<=a)
    {
        k = k+a/i;
        i=i*5;
    }
    return k;
}
int main()
{
    freopen("fact.in","i",stdin);
    freopen("fact.out","u",stdout);
    cin >> p;
    if (p == 0)
    {
        cout << 1;
        return 0;
    }
    p=0;
    l=1;
    r=5*p;
    while(l<=r)
    {
        m=l+(r-l)/2;
        if (n(m) == p)
        b=1;

        if (n(m)>=p)
        r=m-1;
        else l=m+1;
    }
    if (b)
    cout<<l;
    else cout<<-1;
  return 0;
}