Cod sursa(job #3350246)

Utilizator iustinG1314Gorgan Iustin iustinG1314 Data 6 aprilie 2026 17:15:56
Problema Factorial Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
int main()
{
    int n,s=0,x=0;
    cin>>n;
    if(n==0)
    {
        cout<<1;
    }
    else
    {
        int ok=0;
        while(1)
        {
            s+=5;
            int cs=s;
            int l=0;
            while(cs%5==0)
            {
                l++;
                cs/=5;
            }
            x+=l;
            if(x==n)
            {
                ok=1;
                break;
            }
            if(x>n)
            {
                cout<<-1;
                break;
            }
        }
        if(ok==1)
        {
            cout<<s-5;
        }
    }
    return 0;
}