Cod sursa(job #2072566)

Utilizator Andrei_RAndrei Roceanu Andrei_R Data 21 noiembrie 2017 22:43:01
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int main()
{
    int p, i;
    long long n, cn;
    f >> p;
    n = 1;
    i = 0;
    while ( i < p ) {
        i = i*5 + 1;
        n *= 5;
    }
    if ( i != 0 ) {
        i = (i-1) / 5;
        n /= 5;
    }
    for ( ; i < p; i++ ) {
        n += 5;
        cn = n/5;
        while ( cn % 5 == 0 ) {
            i++;
            cn /= 5;
        }
    }
    if ( n == 0 )
        g << "1";
    else
        g << n;
    return 0;
}