Cod sursa(job #2238575)

Utilizator filicriFilip Crisan filicri Data 6 septembrie 2018 13:38:11
Problema Factorial Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int expo (int x)
{
    int exp=0;
    while (x%5==0)
    {
        exp++;
        x/=5;
    }
    return exp;
}
int v[100000004],suma[100000004];
int main()
{
    int p,ok=0;
    f>>p;
    if (p==0) g<<"1";
    else
    {
        for (int i=1;i<=p;i++)
        {
            v[i]=expo(5*i);
            suma[i]=v[i]+suma[i-1];
            if (suma[i]==p)
            {
                g<<5*i;
                ok=1;
                break;
            }
        }
        if (ok==0) g<<"-1";
    }
    f.close();
    g.close();
    return 0;
}