Cod sursa(job #2309070)

Utilizator filiptudose2007Tudose Filip filiptudose2007 Data 28 decembrie 2018 13:37:12
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n;
long long r,pas;
int zero(int x)
{
    int ans=0;
    while(x>=5)
    {
        ans+=x/5;
        x=x/5;
    }
    return ans;
}
int main()
{
    f>>n;
    pas=1<<30;
    r=0;
    while(pas)
    {
        if(zero(r+pas)<n)r+=pas;
        pas/=2;

    }
    if(zero(r+1)==n)
        g<<r+1<<'\n';
    else g<<-1;
    return 0;
}