Cod sursa(job #1526212)

Utilizator dcmionutIonut Deaconu dcmionut Data 16 noiembrie 2015 00:46:57
Problema Factorial Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int get (int b)
{
    int x;
    x = 5 * b;
    for (int i = 25; i <= x; i += 25) {
        int j = i;
        while (j % 25 == 0) {
            x -= 5;
            j /= 5;
        }
    }
    return x;
}
int mult (int b)
{
    b = 5 * b;
    int k = 1;
    for (int i = 25; i <= b; i *= 5) {
        if (i <= b && i * 5 > b)
            return k;
        k++;
    }
}
int main ()
{
    long p, m = 1;
    ifstream f("fact.in");
    ofstream g("fact.out");
    while (f >> p) {
        m = mult (p);
        if (get (p) <= get (p - m))
            g << -1 << endl;
        else g << get (p) << endl;
    }
    f.close ();
    g.close ();
    return 0;
}