题解 P1062 【数列】
(题目为啥要强调用十进制输出呢,明明就是故意提醒)
分析一下样例
转换成三进制就是:
看起来像是二进制,转化成十进制看看
显然,第
程序就把这个过程逆回去,先把
#include <iostream>
#include <stack>
#include <cmath>
using namespace std;
long long k, n, ans;
stack<int> S;
int main() {
cin >> k >> n;
while(n) S.push(n & 1), n >>= 1;
while(!S.empty()) ans += S.top() * pow(k, S.size()-1), S.pop();
cout << ans << endl;
return 0;
}