G - Super Subarray

Super Subarray

 

 

 

 

 

 一个数能被几个数整除,则能被它们的最小公倍数整除

 1 #include <iostream>
 2 #include <bits/stdc++.h>
 3 using namespace std;
 4 typedef long long ll;
 5 const  int maxn = 2010;
 6 const int mod=1e9+7;
 7 ll a[maxn],sum[maxn];
 8 
 9 int main()
10 {
11     int t;
12     scanf("%d",&t);
13     while( t-- ){
14         int n;
15         scanf("%d",&n);
16         sum[0]=0;
17         for(int i=1;i<=n;i++){
18             scanf("%lld",&a[i]);
19             sum[i]=sum[i-1]+a[i];
20         }
21         int ans=0;
22         for(int i=1;i<=n;i++){
23             ll lcm=1;
24             for(int j=i;j<=n;j++){
25                 ll tot = sum[j]-sum[i-1];
26                 lcm = (lcm/__gcd(lcm,a[j]))*a[j];
27                 if( lcm>sum[n]) break;
28                 if( tot%lcm==0 ) ans++;
29             }
30         }
31         printf("%d\n",ans);
32     }
33     return 0;
34 }

 

posted @ 2020-02-05 18:16  swsyya  阅读(158)  评论(0编辑  收藏  举报

回到顶部