This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
long long a[100001];
/*
https://www.actinoi.com/2019/07/21/noip2006%20%E6%99%AE%E5%8F%8A%E7%BB%84/
*/
int main() {
//重定向输入输出
//freopen("sequenc.in", "r", stdin);
//freopen("sequenc.out", "w", stdout);
long long k, n;
cin >> k >> n;
//将n转位二进制
long long i = 1;
while (n) {
a[i++] = n % 2;
n /= 2;
}//注意这是反着的~
//将这个二进制数字当作k进制,再转到十进制
long long q = i - 2, ans = 0;
for (long long j = i - 1; j >= 1; j--) {
ans += a[j] * pow(k, q);
q--;
}
cout << ans << endl;