inline ll expow(ll a, ll b, ll p){ ll res = 1 ; while (b){ if (b & 1) (res *= a) %= p ; (a *= a) %= p, b >>= 1 ; } return res % p ; } inlineboolTest(ll p, ll x){ ll r = 0, d = x - 1 ; while (!(d & 1)) d >>= 1, ++ r ; for (ll i = expow(p, d, x), j ; r ; -- r){ j = i * i % x ; if (j == 1){ if (i == 1 || i == x - 1) return1 ; return0 ; } i = j ; } return0 ; } inlineboolMiller_Rabin(ll x){ if (x == 1) return0 ; for (int i = 0 ; i < 8 ; ++ i){ if (x == Prime[i]) return1 ; if (!(x % Prime[i])) return0 ; if (!Test(Prime[i], x)) return0 ; } return1 ; } ll res[maxn], tot ; inlineintpksrand(){ returnrand() << 15 ^ rand() ; } inline ll Irand(ll x){ return (((ll)pksrand()) << 30 ^ pksrand()) % x ; //2 } inline ll guisuMul(ll a, ll b, ll x){ return (a * b - (ll) ((longdouble) a * b / x + 1e-9) * x) % x; } inline ll qwq(ll x){ ll A = Irand(x), C = Irand(x) ; ll t1 = A, t2 = (guisuMul(A, A, x) + C) % x ; // 1 ll dif = max(t1, t2) - min(t1, t2), G = __gcd(x, dif) ; while (G == 1){ t1 = (guisuMul(t1, t1, x) + C) % x ; t2 = (guisuMul(t2, t2, x) + C) % x ; t2 = (guisuMul(t2, t2, x) + C) % x ; dif = max(t1, t2) - min(t1, t2), G = __gcd(x, dif) ; } return G ; } inlinevoidPollard_Rho(ll x){ if (x == 1) return ; if (Miller_Rabin(x)) { res[++tot] = x; return ; } ll y = x ; while (y == x) y = qwq(x) ; Pollard_Rho(y), Pollard_Rho(x / y) ; }
ll qpow(ll x, int n){ ll r = 1; while (n) { if (n & 1) r = r * x; n >>= 1; x = x * x; } return r; }
int n;
intmain(){ int T; scanf("%d", &T); while (T--) { scanf("%d", &n); int sq = (int)sqrt(1.0 * n); if (sq * sq == n) { puts("infty"); continue; } if (n % 4) { puts("0 0"); continue; } tot = 0; n /= 4; ll m = n; Pollard_Rho(n); ll ans = 1; int cnt = 1; for (int i = 1; i <= tot; i++) { int c = 0; while (n % res[i] == 0) n /= res[i], c++; cnt *= c + 1; ll x = (qpow(res[i], c + 1) - 1) / (res[i] - 1); x %= mod; ans = ans * x % mod; } printf("%d %lld\n", cnt / 2, ans * m % mod); } return0; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<utility> #include<queue> #include<functional> #include<assert.h> #ifdef XLor #define dbg(args...) do {cout << #args << " ->"; err(args);} while (0) #else #define dbg(...) #endif void err() {std::cout << std::endl;} template<typename T, typename...Args> void err(T a, Args...args){std::cout << a << ' '; err(args...);} #define ms(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; typedef pair<int,int> PII; const int mod = 998244353; const int inf = 1 << 30; const int maxn = 2000000 + 5; int n, m, mark[maxn], vis[maxn]; ll ans, tot; vector<PII> edge[maxn]; PII g[maxn]; int dep[maxn], fa[maxn], pre[maxn], siz[maxn]; void dfs(int u, int f) { vis[u] = 1; fa[u] = f; dep[u] = dep[f] + 1; for (auto& x: edge[u]) { int v = x.first; if (vis[v]) continue; if (!mark[x.second]) continue; // mark[x.second] = 1; dfs(v, u); } } int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); } ll cal(ll x) { return x * (x - 1) / 2; } struct node { int u, v, id; bool operator<(const node& b) const { return id > b.id; } }; void kruskal() { priority_queue<node> pq; for (int i = 1; i <= m; i++) pq.push({g[i].first, g[i].second, i}); while (!pq.empty()) { node x = pq.top(); pq.pop(); int u = find(x.u), v = find(x.v); if (u == v) continue; mark[x.id] = 1; pre[u] = v; } } int main() { int T; scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { edge[i].clear(); vis[i] = 0; pre[i] = i; siz[i] = 1; } for (int i = 1; i <= m; i++) { mark[i] = 0; scanf("%d%d", &g[i].first, &g[i].second); edge[g[i].first].push_back({g[i].second, i}); edge[g[i].second].push_back({g[i].first, i}); } kruskal(); for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i, 0); for (int i = 1; i <= n; i++) pre[i] = i; ans = tot = 0; for (int i = 1; i <= m; i++) { if (mark[i]) { dbg(i, tot); ans ^= tot * i; continue; } int u = find(g[i].first), v = find(g[i].second); vector<int> vec; while (u != v) { if (dep[u] < dep[v]) swap(u, v); vec.push_back(u); u = find(fa[u]); } assert(u == v); tot -= cal(siz[u]); for (int& x: vec) { if (x == u) continue; tot -= cal(siz[x]); pre[x] = u; siz[u] += siz[x]; } tot += cal(siz[u]); dbg(i, tot, u, siz[u]); ans ^= tot * i; } printf("%lld\n", ans); } return 0; }