kyopro_library

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

View the Project on GitHub dyktr06/kyopro_library

:heavy_check_mark: test/yukicoder/yuki_2087.test.cpp

Depends on

Code

#define PROBLEM "https://yukicoder.me/problems/no/2087"
#include <bits/stdc++.h>
using namespace std;

#include "../../lib/math/convert_base.hpp"

int main(){
    int n, m; cin >> n >> m;
    cout << convertBase(m, n) << "\n";
}
#line 1 "test/yukicoder/yuki_2087.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/2087"
#include <bits/stdc++.h>
using namespace std;

#line 2 "lib/math/convert_base.hpp"

/**
 * @brief Convert Base (進数変換)
 * @docs docs/math/convert_base.md
 */

template<typename T>
string convertBase(T x, int b) {
    string res;
    T t = 1, k = abs(b);
    while(x){
        T num = (x * t) % k;
        if(num < 0) num += k;
        res += num + (num < 10 ? 48 : 87);
        x -= num * t;
        x /= k;
        t *= b / k;
    }
    if(res.empty()) res = '0';
    reverse(res.begin(), res.end());
    return res;
}
#line 6 "test/yukicoder/yuki_2087.test.cpp"

int main(){
    int n, m; cin >> n >> m;
    cout << convertBase(m, n) << "\n";
}
Back to top page