https://programmers.co.kr/learn/courses/30/lessons/17687#
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
string getS(int num, int n){
string ret = "";
if(num == 0)
return "0";
while(num != 0){
int r = num%n;
if(r > 9){
ret += string(1, 'A'+(r-10));
}else
ret += to_string(r);
num = num/n;
}
reverse(ret.begin(), ret.end());
return ret;
}
string solution(int n, int t, int m, int p) {
string answer = "";
p--;
int sum = 0;
int digitN;
int digit = 1;
int startN = 0;
while(t != 0){
if(digit == 1) digitN = n;
else digitN = (n-1) *pow(n, digit-1);
if(sum+digitN*digit >= p){
int next = (p - sum) / (digit); // 앞으로 몇번
int idx = (p - sum) % (digit);
int number = startN + next; // n진법을 구해야하는 수
char c = getS(number, n)[idx];
answer +=c;
t--;
p = p+m;
}else{
startN += digitN; // 시작 숫자
sum += digitN * digit; // 자릿수 합
digit++;
}
}
return answer;
}
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
char number[18] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
string number_to_n(int num, int n){
string result;
if(num == 0){
return "0";
}
while(num > 0){
result += number[num % n];
num /= n;
}
reverse(result.begin(), result.end());
return result;
}
string solution(int n, int t, int m, int p) {
string answer = "";
string temp;
int mt = m * t;
for(int num = 0; temp.size() <= mt; num++){
string ngame = number_to_n(num, n);
temp += ngame;
}
for(int i = 0; i < t; i++){
answer += temp.at((m*i)+(p-1));
}
return answer;
}