Cod sursa(job #2103480)

Utilizator andreisontea01Andrei Sontea andreisontea01 Data 10 ianuarie 2018 13:04:50
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <cstdio>
#include <iostream>

using namespace std;

int zerouri(int x){
    int puter = 5, rez = 0;
    while(puter <= x){
        rez += x / puter;
        puter *= 5;
    }
    return rez;
}

int main()
{
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);
    int p;
    scanf("%d", &p);
    int pas = 1 << 30, rasp = 0;
    while(pas){
        if(zerouri(pas + rasp) <= p)
            rasp += pas;
        pas /= 2;
    }
    rasp -= 4;
    if(p == 0)
        rasp = 1;
    if(zerouri(rasp) != p)
        printf("-1");
    else
        printf("%d", rasp);
    return 0;
}