Cod sursa(job #2431406)

Utilizator Alex18maiAlex Enache Alex18mai Data 19 iunie 2019 12:20:21
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <fstream>
#include <cmath>

using namespace std ;

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

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;

    long long now = 0;

    for (int i=0; i<=1e5; i++){
        //verific now -> pilonul actual
        //verific now + 1e5 -> urmatorul pilon
        //daca se respecta conditia -> verific intervalul now -> now + 1e5
        long long A = zero (now);
        long long B = zero (now + 1e5);
        if (A <= p && B >= p){
            //ne-am gasit intervalul
            for (long long j=now; j<=now+1e5; j++){
                if (zero(j) == p){
                    cout<<j;
                    return 0;
                }
            }
        }
        now += 1e5;
    }

    cout<<-1;

    return 0;
}