被好几道给卡了
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <set> #include <vector> #include <queue> #include <algorithm> using namespace std; #define SE second #define FI first #define MP(x,y) make_pair(x,y) const int MAXN = 30010; const int MAXM = 110; const int MOD = 1000000007; const int INF =1000000007; int sa[MAXN]; int arr[MAXN],brr[MAXN],suma[MAXN],sumb[MAXN],cnta[MAXN],cntb[MAXN]; pair<int,int> pa[MAXM]; long long cal(int a,int b,int n,int m) { int tmpsa=0; long long bnum=0; for(int i=a;i<MAXN;i+=a) tmpsa-=sa[i]; memset(cnta,0,sizeof(cnta)); memset(cntb,0,sizeof(cntb)); suma[0]=arr[0]%a; for(int i=1;i<n;++i) suma[i]=(suma[i-1]+arr[i])%a; sumb[0]=brr[0]%b; for(int i=1;i<m;++i) sumb[i]=(sumb[i-1]+brr[i])%b; cntb[0]=1; for(int i=0;i<m;++i) bnum+=cntb[sumb[i]]++; cnta[0]=1; for(int i=0;i<n;++i) tmpsa+=(cnta[suma[i]]++); if(sa[a]==0) sa[a]=tmpsa; return bnum*tmpsa; } int main() { int ncase,n,m,c,ptop; long long ans; scanf("%d",&ncase); while(ncase--) { ans=0; ptop=0; memset(sa,0,sizeof(sa)); scanf("%d%d%d",&n,&m,&c); for(int i=0;i<n;++i) scanf("%d",&arr[i]); for(int i=0;i<m;++i) scanf("%d",&brr[i]); for(int i=1;i*i<=c;++i) if(c%i==0) { ans+=cal(c/i,i,n,m); pa[ptop++]=MP(c/i,i); } for(int i=0;i<ptop;++i) ans+=cal(pa[i].SE,pa[i].FI,n,m); cout<<ans<<"\n"; } return 0; }