在3~15的范围内,可以证明第k大的项就是将k转化成2进制表示,其2进制表示对应相应次幂的项是否需要累加
// Problem#: 1344
// Submission#: 2694846
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int k, n, arr[100];
while(cin >> k >> n) {
int r = 0, s = 0;
while (n > 0) {
arr[r++] = n % 2;
n /= 2;
}
for (int i = 0;i < r; ++i)
s += pow(double(k), double(i)) * arr[i];
cout << s << endl;
}
}