思路:
直接dfs搜索,答案不会太大
c o d e code code
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
ll t, n, k;
ll ans;
void dfs(ll x, ll y, ll sum) {
if(x == 1) {
ans = min(ans, sum);
return ;
}
if(y != 0) dfs(x / 2 + 1, y - 1, sum + 1);
ll g = x;
for(ll i = 2; i * i <= x; i ++) {
if(x % i == 0) {
g = g * (i - 1) / i;
while(x % i == 0) x = x / i;
}
}
if(x > 1) g = g * (x - 1) / x;
dfs(g, y, sum + 1);
}
int main() {
freopen("func.in", "r", stdin);
freopen("func.out", "w", stdout);
scanf("%lld", &t);
while(t --) {
scanf("%lld%lld", &n, &k);
ans = 1e9;
dfs(n, k, 0);
printf("%lld\n", ans);
}
return 0;
}