Files
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

28 lines
674 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;
typedef long long LL;
/*
离散化的思想。映射到2进制(不会改变任何一位的顺序,
因为k>=3 题意那些k进制表达的数严格单调,就像 1100 > 1011 每位都是排好顺序),
然后看它二进制表示中每一位是1还是0,然后再逆映射回十进制.
*/
LL get(int a, int b) { // a^b
LL res = 1;
while (b--) res *= a;
return res;
}
int main() {
int n, k;
cin >> k >> n;
LL res = 0;
for (int i = 0; i < 20; i++) // N=1000, 3^?=1000
if (n >> i & 1)
res += get(k, i);
cout << res << endl;
return 0;
}