let menu = ["Home", "Algorithms", "CodeHub", "VNOI Statistics"];

Overview

ILSMATH - Đếm số giai thừa

solution.md

X là số có N chữ số nếu \(\lceil \log X \rceil = N\), trong đó \(\lceil \log X \rceil\) là phép làm tròn trên, tương đương với hàm ceil() trong ngôn ngữ lập trình.

Ngoài ra, ta có \(\log (AB) = \log A + \log B\), vì vậy:

\[\log X! = \log 1 + \log 2 + \dots + \log X\]
main.cpp
Open in Github Download
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    int n; cin >> n;
    vector<int> res;

    double sum = 0;
    for (int i=1; ceil(sum) <= n; i++) {
        sum += log10(i);
        if (ceil(sum) == n) res.push_back(i);
    }

    if (res.empty()) cout << "NO";
    else {
        cout << res.size() << "\n";
        for (int x: res) cout << x << "\n";
    }
    return 0;
}
Comments