serna37's Library

Logo

C++ アルゴリズムとデータ構造のライブラリ

View the Project on GitHub serna37/library-cpp

:heavy_check_mark: 階乗
(library/number/factorial.hpp)

階乗

できること

計算量

$O(N)$

使い方

long long fac = factorial(N);

Verified with

Code

#pragma once
long long factorial(int N) {
    long long res = 1;
    while (N > 0) res *= N--;
    return res;
}
#line 2 "library/number/factorial.hpp"
long long factorial(int N) {
    long long res = 1;
    while (N > 0) res *= N--;
    return res;
}
Back to top page