Cod sursa(job #2690391)

Utilizator andrei_marciucMarciuc Andrei andrei_marciuc Data 23 decembrie 2020 20:49:40
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream>
using namespace std;
unsigned long long p, x, nr, k;
ifstream cin( "fact.in" );
ofstream cout( "fact.out" );

int main()
{
    cin >> p;
    if( p == 0 )
        cout << 1;
    else {
        x = 5 * ( p - p / 5 );
        while( nr < p ){
            nr = 0;
            k = 5;
            while( k <= x ){
                nr += x / k;
                k *= 5;
            }
            if( nr < p )
                x += 5;
        }
        if( nr == p )
            cout << x;
        else cout << -1;
    }
}