Cod sursa(job #1588472)

Utilizator teodor440Teodor Tonghioiu teodor440 Data 3 februarie 2016 09:08:04
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>

using namespace std;

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


int p[26];

int next(){
    int i = 0, r = 1;
    p[i]++;
    while(p[i] % 5 == 0 && p[i] != 0){
        r++;
        p[i+1]++;
        p[i++] = 0;
    }
    return r;
}

int main()
{
    long n, pz = 0, s = 0, i;
    f >> n;
    for(i = 0; i <= 25; i++) p[i] = 0;

    if(n == 0){
        g << 1;
        return 0;
    }

    while(pz < n){
        pz += next();
        s += 5;
    }

    if(pz == n) g << s;
    else g << -1;

    return 0;
}