library

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

View the Project on GitHub rajyan/library

:heavy_check_mark: src/ctz.hpp

Depends on

Required by

Verified with

Code

#pragma once

#include "popcount.hpp"

using lint = long long;

inline int ctz(lint n) {
    return popcount(~n & (n - 1));
}
#line 2 "src/ctz.hpp"

#line 2 "src/popcount.hpp"

using lint = long long;

inline int popcount(lint n) {
    n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555);
    n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333);
    n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f);
    n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff);
    n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff);
    n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff);
    return n;
}
#line 4 "src/ctz.hpp"

using lint = long long;

inline int ctz(lint n) {
    return popcount(~n & (n - 1));
}
Back to top page