/ Vijos / 讨论 / 货币 /

RE救救我,最后一个点

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cctype>
#define debug(x) cerr << #x << " = " << x << endl
#define LL long long
#define MAXN 40000010
using namespace std;
inline LL read(){
LL x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
return x * f;
}

LL f[MAXN];
LL T, n;

map<LL, int> mp;
int tot = 0;

inline LL dfs(LL x){
if(!mp[x]) mp[x] = ++tot;
if(x > x / 2 + x / 3 + x / 4) return f[mp[x]] = x;
if(f[mp[x]]) return f[mp[x]];
return f[mp[x]] = dfs(x / 2) + dfs(x / 3) + dfs(x / 4);
}

int main(){
T = read();
while(T--){
n = read();
cout << dfs(n) << endl;
}
return 0;
}

//救命啊,就是最后一个点

0 条评论

目前还没有评论...

信息

ID
1599
难度
7
分类
搜索 | 记忆化搜索 点击显示
标签
(无)
递交数
2480
已通过
414
通过率
17%
被复制
4
上传者