? ( ⌊ ? 2 ⌋ ) + ? ( ⌊ ? 3 ⌋ ) f(k)=f(⌊ 2 k ⌋)+f(⌊ 3 k ⌋) 对于任意正整数 ? k 。 请你求出 ? ( ? ) f(n) 。 输入格式 输入一行一个正整数 ? n 。 保证 1 ≤ ? ≤ 1 0 18 1≤n≤10 18 。 输出格式。 输出一行一个整数,表示答案。 样例 1 输入 2 输出 3
代码:无输出(C++)
#include<bits/stdc++.h>
using namespace std;
map<long long,unsigned long long>mp;
unsigned long long dfs(unsigned long long x){
unsigned long long res1=mp[x/2];
if(res1==0){
res1+=dfs(x/2);
}
unsigned long long res2=mp[x/3];
if(res2==0){
res2+=dfs(x/3);
}
return res1+res2;
}
unsigned long long int n;
int main(){
cin>>n;
cout<<dfs(n);
return 0;
}