Cod sursa(job #3245831)

Utilizator obsidianMidnight Majesty obsidian Data 30 septembrie 2024 20:20:46
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int count_factors_of_5(int n) {
    int count = 0;
    while (n > 0) {
        n /= 5;
        count += n;
    }
    return count;
}

int find_smallest_N_with_exactly_P_zeros(int p) {
    int low = 0, high = p * 5;
    while (low < high) {
        int mid = (low + high) / 2;
        if (count_factors_of_5(mid) < p) {
            low = mid + 1;
        } else {
            high = mid;
        }
    }
    return low;
}

int main() {
    int p;
    fin >> p;
    if (p == 0) {
        fout << 1;
    } else {
        fout << find_smallest_N_with_exactly_P_zeros(p);
    }
    return 0;
}