Cod sursa(job #1527081)

Utilizator flibiaVisanu Cristian flibia Data 17 noiembrie 2015 19:55:22
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
 
using namespace std;
 
int lol(int x, int y)
{
    if(x % 5 != 0)
        return y;
    else
    {
        y++;
        return lol(x / 5, y);
    }
} 
     
int main()
{
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    int a, k;
    fin >> a;
    int b;
    int suma = 0;
    int j = 1;
    while (suma < a)
    {
        k = 1;
        b = lol(j, k);
        suma += b;
        j++;
    }   
    if(a == 0)
        fout << 1;
    else
        if (suma == a) 
            fout << ((j-1) * 5);
        else
            fout << "-1";
    fin.close();
    fout.close();
    return 0;
}