Cod sursa(job #2543285)

Utilizator amalia.gemanGeman Aamalia amalia.geman Data 10 februarie 2020 23:56:27
Problema Factorial Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int nr0;

int Desc5(int x)
{
    int ct=0;
    while(x%5==0)
        ct++, x/=5;
    return ct;
}

int main()
{
    int n=0, k, prod, x, test=0;

    fin >> nr0;
    if(nr0==0)
    {
        fout<<1;
        return 0;
    }

    n=0;
    k=1;
    while(test==0)
    {
        x=Desc5(k); k++;
        x++;
        if(nr0-x >=0)
            nr0-=x;
        else test=2;
        n+=5;
        if(nr0==0)
            test=1;
    }

    if(test==2)
        fout << -1;
    else fout << n;
    return 0;
}