// Problem: 小Why的数论测试 // Contest: NowCoder // URL: https://ac.nowcoder.com/acm/contest/64384/F // Memory Limit: 524288 MB // Time Limit: 2000 ms
#include<bits/stdc++.h> #define endl '\n' #define int long long usingnamespace std; using ll = longlong;
bool multi = 1;
unordered_map<int,int> mp; int a,b;
intdfs(int x){ if(mp.count(x)) return mp[x]; int ans = x - a; if(x / 2 >= a) ans = min(ans, dfs(x / 2) + 1 + x % 2); int u = sqrt(x); if(u >= a) ans = min(ans, dfs(u) + 1 + x - u * u); return mp[x] = ans; }