Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
30741 | LYLAKIOI | 【S】T1 | C++ | 通过 | 100 | 2768 MS | 96888 KB | 1926 | 2024-07-30 13:04:06 |
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define p_b push_back #define m_p make_pair #define p1 first #define p2 second using namespace std; typedef long long ll; const int maxn=1e6+10,mod=998244353; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; }int n,a[maxn],pr[maxn],fl[maxn],C; int S[maxn][22],ind[maxn]; int qpow(int a,int b){ int res=1; while(b){ if(b&1)res=res*1ll*a%mod; a=a*1ll*a%mod,b>>=1; }return res; } void init(){ up(i,2,1e6){ if(!fl[i])pr[++C]=i; up(j,2,int(1e6)/i)fl[i*j]=0; } } void slv(){ n=read();up(i,1,n)a[i]=read(); up(i,1,n){ int x=a[i]; for(int w=1;pr[w]*pr[w]<=x;++w){ int j=pr[w]; if(x%j)continue;int c=0; while(!(x%j))x/=j,c++; up(k,0,20)S[j][k]=0;ind[j]=20; }if(x!=1){ up(k,0,20)S[x][k]=0;ind[x]=20; } } set<int>st; up(i,1,n){ int x=a[i]; for(int w=1;pr[w]*pr[w]<=x;++w){ int j=pr[w]; if(x%j)continue;int c=0; while(!(x%j))x/=j,c++; S[j][c]++;st.insert(j); }if(x!=1)S[x][1]++,st.insert(x); }int res=0; while(n--){ int M=1;vector<int>DEL; for(auto it:st){ while(ind[it]&&(!S[it][ind[it]]))--ind[it]; if(!ind[it])DEL.p_b(it); else { M=M*1ll*qpow(it,ind[it])%mod; S[it][ind[it]]--; } }for(int x:DEL)st.erase(x); (res+=M)%=mod; }printf("%d\n",res); }int main(){ init();int t=read();while(t--)slv(); fclose(stdin); fclose(stdout); return 0; }