Files
python/TangDou/XiTi/1186.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

30 lines
701 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}