Cod sursa(job #1991470)

Utilizator Alex18maiAlex Enache Alex18mai Data 16 iunie 2017 21:58:58
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <cmath>

using namespace std ;

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

long long zero (long long x) {
    long long S = 0 ;
    while ( x / 5LL ) {
        S = S + (x / 5LL) ;
        x = x / 5LL ;
    }
    return S ;
}

int main()
{
    int p;
    cin>>p;
    int vmax= (p+1) * 5;
    int rad = (int)sqrt((double)vmax);
    for (int i=1; i<=vmax; i+=rad){
        if (zero(i)>=p){
            for (int j=max(i-rad,1); j<=i; j++){
                if (zero(j)==p){
                    cout<<j;
                    return 0;
                }
            }
        }

    }
    cout<<-1;
    return 0;
}