#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
ull n,k;
void f(ull x,ull cishu){
if(cishu<=0){
cout<<x;
exit(0);
}
if(x%3==0){
if(cishu<3){
cout<<x+cishu;
exit(0);
}
x+=3;
x/=3;
f(x,cishu-3);
}else if(x%3==1){
if(cishu<2){
cout<<x+cishu;
exit(0);
}
x+=2;
x/=3;
f(x,cishu-2);
}else{
x++;
x/=3;
f(x,cishu-1);
}
}
int main(){
cin>>n>>k;
f(n,k);
return 0;
}
递归思想,k 到 1018 就 MLE 过不去。
暴力思想,TLE 过不去。