Cod sursa(job #2285380)

Utilizator CosaMateiMatei Cosa Gabriel CosaMatei Data 18 noiembrie 2018 15:20:10
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("fact.in");
ofstream out("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()
{
    in>>n;
    pas=1<<30;
    r=0;
    while(pas!=0)
    {
        if (Zero(r+pas)<n)
        {
            r+=pas;
        }
        pas/=2;
    }
    if (Zero(r+1)==n)
        out<<r+1<<'\n';
    else out<<-1;
    return 0;
}