Cod sursa(job #2772405)

Utilizator Gabryel9898Bizdoc Vasile Gabriel Gabryel9898 Data 1 septembrie 2021 02:36:05
Problema Factorial Scor 65
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <iostream>
#include <chrono>
#include <fstream>

using namespace std::chrono;

std::ifstream f1("fact.in");
std::ofstream f2("fact.out");


long long zeros(long long n) {
    long long res = 0;
    while (n = n / 5) {
        res += n;
    }
    return res;
}

void factorial() {
    int target;
//    std::ifstream f1("../in.txt");
//    std::ofstream f2("../out.txt");

    f1 >> target;

    long long end = 1e10;
    long long start = 1;
    long long zr;
    long long half;
    do {
        half = (start + end) / 2;
        zr = zeros(half);
        if (zr > target) {
            end = half;
        } else {
            start = half;
        }
    } while (zr != target);

    int endWith = start % 10;

    if (endWith > 5) {
        start -= endWith;
        start += 5;
    } else {
        start -= endWith;
    }

    f2 << start;
}


int main() {
    auto start = high_resolution_clock::now();

    factorial();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<milliseconds>(stop - start);
    std::cout << std::endl << "[time]:" << duration.count() << std::endl;
    return 0;
}