Cod sursa(job #1469252)

Utilizator FairPlay94George Cioroiu FairPlay94 Data 7 august 2015 20:21:00
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <climits>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <map>
#include <algorithm>

using namespace std;

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

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int p;
    cin >> p;
    if (p == 0) {
        cout << 1;
        return 0;
    }
    int st = 1, dr = 5 * p;
    while (st <= dr) {
        int mid = (st + dr) / 2, aux = mid, total = 0;
        while (aux > 0) {
            aux /= 5;
            total += aux;
        }
        if (total == p) {
            cout << 5 * (mid / 5);
            return 0;
        }
        if (total < p)
            st = mid + 1;
        else
            dr = mid - 1;
    }
    cout << -1;

    return 0;
}