Cod sursa(job #1652781)

Utilizator flaviu_2001Craciun Ioan-Flaviu flaviu_2001 Data 15 martie 2016 13:58:04
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <cstdio>
#define MAXVAL 0x3fffffff

using namespace std;

int zeros(int val)
{
    int rez = 0;
    for (int i = 5; i <= val; i*=5)
        rez += val / i;
    return rez;
}

int main()
{
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);

    int p;
    scanf("%d", &p);
    int step;
    for (step = 1; step < MAXVAL; step <<= 1);
    int rez = MAXVAL, aux;
    for (int i = 1; step; step >>= 1)
        if (rez - step > 0 && zeros(rez - step) >= p)
            rez -= step;
    if (zeros(rez) == p)
        printf("%d", rez);
    else
        printf("%d", -1);

    return 0;
}