Cod sursa(job #1769467)

Utilizator papinub2Papa Valentin papinub2 Data 2 octombrie 2016 16:16:32
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>

using namespace std;

ifstream in("fact.in");
ofstream out("fact.out");

long long rez(int x)
{
    long long nr=0;
    while (x>=5)
    {
        nr=nr+x/5;
        x=x/5;
    }
    return nr;
}

int main ()
{
    int n, k=0, x;
    in>>n;
    if (n==0)
        out<<1;
    if (rez(n*5)==n)
        out<<n*5;
    else
    {
        while (rez(n*5-k)>=n)
            k=k+5;

        if (rez(n*5-k) == n)
            out<<n*5-k;
        else
            out<<-1;
    }
    return 0;
}