library

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

View the Project on GitHub matumoto1234/library

:warning: math/to-base.hpp

Depends on

Code

#pragma once

#include "./base.hpp"

#include <algorithm>
#include <vector>

namespace matumoto {
  // decimal n -> b-ary
  template <typename T>
  vector<T> to_base(T n, T b) {
    if (n == 0 or b <= 1)
      return vector<T>{ 0 };
    vector<T> res;
    for (; n > 0; n /= b) {
      res.emplace_back(n % b);
    }
    reverse(res.begin(), res.end());
    return res;
  }
} // namespace matumoto
#line 2 "math/to-base.hpp"

#line 2 "math/base.hpp"

namespace matumoto {
  using namespace std;
  using ll = long long;
} // namespace matumoto
#line 4 "math/to-base.hpp"

#include <algorithm>
#include <vector>

namespace matumoto {
  // decimal n -> b-ary
  template <typename T>
  vector<T> to_base(T n, T b) {
    if (n == 0 or b <= 1)
      return vector<T>{ 0 };
    vector<T> res;
    for (; n > 0; n /= b) {
      res.emplace_back(n % b);
    }
    reverse(res.begin(), res.end());
    return res;
  }
} // namespace matumoto
Back to top page