Cod sursa(job #2779984)

Utilizator andrei_srbnSerban Andrei andrei_srbn Data 5 octombrie 2021 17:39:29
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int factorial(int n)
{
    int ct;
    ct=0;
    while(n)
    {
        ct+=n/5;
        n=n/5;
    }
    return ct;
}
int main()
{
    int p;
    fin>>p;
    int zerouri;
    int s,d,m;
    int sol=-1;
    s=1;
    if(p==0)return 1;
    d=500000000;
    while(s<=d)
    {
        m=(s+d)/2;
        zerouri=factorial(m);
        if(zerouri<p)
            s=m+1;
        else if(zerouri>p)
            d=m-1;
        else
        {
            sol=m;
            break;
        }

    }
      if(sol!=-1)sol=sol-sol%5;

      fout<<sol;

    return 0;
}