Cod sursa(job #2155515)

Utilizator Andrei_RAndrei Roceanu Andrei_R Data 7 martie 2018 21:42:37
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int x;

int zero( int n ) {
    x = 0;
    while ( n > 0 ) {
        x = x + n/ 5;
        n /= 5;
    }
    return x;
}

int main()
{
    int r , pas, g;
    in >> g;
    if ( g == 0 ) {
        out << 1;
        return 0;
    }
    r = 0;
    pas = 1 << 30;
    while ( pas != 0 ) {
        if ( zero(r+pas) <= g ) {
            r += pas;
        }
        pas /= 2;
    }
    if ( zero(r) == g )
        out << r-4;
    else
        out << "-1";
    return 0;
}