You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
701 B

2 years ago
#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;
}