The number of thumb ups;
General idea:
For the case of type = 1, it is considered that there is an approximate number of X-K in X, and the minimum value of X, the X-K> 0 is converted to the approximate number of B + K as B,
We know the approximate number of (B + k) <= 2 * SQRT (B + k); this should be known,
To simplify it, B * B <= 4 (B + k) can enumerate B directly. Some people are worried about it. Let's prove it again:
Simplified: B * B-4 * B + 4 <= 4 * k + 4; then K <= 47777, so you can enumerate ..
If type = 0, we can obtain the minimum number of X numbers in advance, because the equation N = A [1] ^ X1 + A [2] ^ x2 .....;
Num = (1 + X1) * (1 + x2 )*....;
Here we can search for DFS. Take a look at the code to understand
# Include <cstdio> # include <algorithm> # include <cmath> # include <string. h> typedef long ll; using namespace STD; # define maxn 200000 const long INF = (1ll <62) + 1; int prime [maxn]; ll a [maxn * 10]; int B [maxn * 2], T; void PRI () {for (INT I = 2; I * I <maxn; I ++) if (! B [I]) for (Int J = I * 2; j <maxn; j + = I) B [J] = 1; for (INT I = 2; I <maxn; I ++) if (! B [I]) prime [++ T] = I;} int get (ll x) {int ans = 1; ll TMP = x; For (INT I = 1; prime [I] <= tmp/prime [I]; I ++) {ll T = 1; while (TMP % prime [I] = 0) {T ++; TMP/= prime [I];} If (T> 1) ans * = T;} If (TMP! = 1) ans * = 2; return ans;} void DFS (int I, ll X, int N) // DFS part {If (n> 47777) return; if (x <INF & (A [n] = 0 | A [n]> X) A [n] = X; // For (Int J = 1; j <= 62; j ++) {If (INF/prime [I] <X) break; // prevent overflow, x * = prime [I]; If (x> = inf) break; DFS (I + 1, x, N * (J + 1) ;}} void solve1 (int x) {if (a [x]! = 0) printf ("% i64d \ n", a [x]); else printf ("INF \ n");} void solve (ll x) {ll num = 1; while (Num * num <= (Num + x) * 4) {If (num = get (Num + x )) {printf ("% i64d \ n", num + x); return;} num ++;} printf ("illegal \ n");} int main () {int t; scanf ("% d", & T); PRI (); DFS (1, 1); For (int o = 1; O <= T; O ++) {printf ("case % d:", O); int type, K; scanf ("% d", & type, & K ); if (type) solve (k); else solve1 (k);} return 0 ;}