Cod sursa(job #3245830)

Utilizator obsidianMidnight Majesty obsidian Data 30 septembrie 2024 20:17:26
Problema Factorial Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 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;
    fout << find_smallest_N_with_exactly_P_zeros(p);
    return 0;
}