Library-Python

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

View the Project on GitHub Rin204/Library-Python

make_popcount
(expansion/misc/make_popcount.py)

概要

popcount を求めるための関数を出力します.

使い方

make_popcount(n) 

で n bit までの popcount を求めることができる関数を出力します.

Code

def make_popcount(n):
    print("def popcount(x):")
    le = 1
    while le < n:
        le *= 2
    five = "5" * n
    print(f"    x = (x & 0x{five}) + ((x >> 1) & 0x{five})")
    three = "3" * n
    print(f"    x = (x & 0x{three}) + ((x >> 2) & 0x{three})")
    d = 1
    shift = 4
    while shift < le:
        S = []
        for _ in range((le + 2 * d - 1) // (2 * d)):
            S += ["0"] * d
            S += ["f"] * d
        S = "".join(S[-n:])
        print(f"    x = (x & 0x{S}) + ((x >> {shift}) & 0x{S})")
        shift <<= 1
        d <<= 1
    print("    return x")
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/onlinejudge_verify/documentation/build.py", line 81, in _render_source_code_stat
    bundled_code = language.bundle(
                   ^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/onlinejudge_verify/languages/python.py", line 108, in bundle
    raise NotImplementedError
NotImplementedError
Back to top page