函数的魔法
裸的直接写就好了。
#include <bits/stdc++.h> using namespace std; const int mod = 233; int vis[mod + 10]; typedef pair<int, int> pii; int f(int x) { return (1ll * x * x % mod * x % mod + 1ll * x * x % mod) % mod; } int g(int x) { return (1ll * x * x % mod * x % mod - 1ll * x * x % mod + mod) % mod; } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int T; scanf("%d", &T); while(T--) { memset(vis, 0, sizeof vis); queue<pii> q; int a, b; scanf("%d %d", &a, &b); if (a == b) { puts("0"); continue; } else if (b >= mod) { puts("-1"); continue; } else if (a >= mod) { int x = f(a), y = g(a); vis[x] = vis[y] = 1; q.push(make_pair(x, 1)); q.push(make_pair(y, 1)); } else { vis[a] = 1; q.push(make_pair(a, 0)); } int ans = -1; while(q.size()) { auto it = q.front(); q.pop(); if (it.first == b) { ans = it.second; break; } int a = f(it.first), b = g(it.first); if (!vis[a]) { vis[a] = 1; q.push(make_pair(a, it.second + 1)); } if (!vis[b]) { q.push(make_pair(b, it.second + 1)); } } printf("%d\n", ans); } return 0; }