Neterukun's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Neterukun1993/Library

:heavy_check_mark: 約数列挙 (試し割り法)
(NumberTheory/Prime/divisors.py)

概要

$O(\sqrt n)$ で約数列挙を行うアルゴリズム。

使い方

divisors(n: int) -> List[int]
整数 n の約数を昇順列挙した結果のリストを返す。計算量 $O(\sqrt n)$

Verified with

Code

def divisors(n):
    divs = []
    for k in range(1, int(n ** 0.5) + 1):
        if n % k == 0:
            divs.append(k)
            if k != n // k:
                divs.append(n // k)
    divs = sorted(divs)
    return divs
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/python.py", line 96, in bundle
    raise NotImplementedError
NotImplementedError
Back to top page