sotanishy's competitive programming library

sotanishy's code snippets for competitive programming

View the Project on GitHub sotanishy/cp-library-cpp

:warning: Base Conversion
(math/convert_base.cpp)

Description

10進数の整数 $n$ を $base$ 進数に変換する

Operations

Code

#pragma once
#include <vector>

std::vector<int> convert_base(int n, int base) {
    int q = n / base, r = n % base;
    if (q == 0) return {r};
    auto ret = convert_base(q, base);
    ret.push_back(r);
    return ret;
}
#line 2 "math/convert_base.cpp"
#include <vector>

std::vector<int> convert_base(int n, int base) {
    int q = n / base, r = n % base;
    if (q == 0) return {r};
    auto ret = convert_base(q, base);
    ret.push_back(r);
    return ret;
}
Back to top page