Cod sursa(job #1769438)

Utilizator papinub2Papa Valentin papinub2 Data 2 octombrie 2016 15:41:55
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 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;
    in>>n;
    if (rez(n*5)==n) {out<<n*5; return 0;}
    else
    {
        while (rez(n*5-k)!=n)
        {
            k=k+5;
        }
        out<<n*5-k;
        return 0;
    }
}