Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
30850 | 沈仲恩 | 【S】T1 | C++ | 通过 | 100 | 1555 MS | 34476 KB | 2223 | 2024-07-30 21:24:37 |
#include <bits/stdc++.h> #define int long long #define mod 998244353 #define fir first #define sec second using namespace std; int t, n, a; queue <int> q; inline int ksm(int x, int y) { int res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod, y >>= 1; } return res; } vector<int>G[1000010]; set<int>st; vector<int>ers; signed main() { //int sttt = clock(); //freopen("inequality.in", "r", stdin); //freopen("inequality.out", "w", stdout); // for (int i = 2; i <= 1000000; i++) // inv[i] = (mod - mod / i) % mod * inv[i - 1] % mod; // inv[i] = ksm(i, mod - 2); // printf("%lld %lld\n", 2 * inv[2] % mod, 6 * inv[3] % mod); scanf("%lld", &t); while (t--) { scanf("%lld", &n); int ans = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &a); for (int j = 2; j * j <= a; j++) { if (a % j == 0) { int cnt = 0; while (a % j == 0) cnt++, a /= j; G[j].push_back(cnt);st.insert(j); } } if(a!=1){ G[a].push_back(1);st.insert(a); } } for (auto p : st) sort(G[p].begin(), G[p].end()); // for(auto p:st){ // cout<<p<<":"<<endl; // for(auto o:G[p]){ // cout<<o<<" "; // }cout<<endl; // } int cur; for (int i = 1; i <= n; i++) { cur = 1;ers.clear(); for (auto p : st) { cur = cur * ksm(p, *G[p].rbegin()) % mod; // cout<<p.fir<<"."<<p.sec[p.sec.size()-1]<<" "; G[p].pop_back(); if (G[p].empty())ers.push_back(p); } for(auto o:ers)st.erase(o); // cout<<endl; ans = (ans + cur) % mod; } printf("%lld\n", ans); } // printf("Run time:%lldms", (clock() - sttt) * 1000 / CLOCKS_PER_SEC); return 0; }