In this problem, subarray is defined as non-empty sequence of consecutive elements.
We define a subarray as Super Subarray if the summation of all elements in the subarray is divisible by each element in it.
Given an array a of size n, print the number of Super Subarrays in a.
Input
The first line of the input contains a single integer T (1 ≤ T ≤ 100), the number of test cases.
The first line of each test case contains one integer n (1 ≤ n ≤ 2000), the length of array a.
The second line of each test case contains the sequence of elements of the arraya1, a2, ..., an (1 ≤ ai ≤ 109), ai is the i-th element of the array a.
Output
For each test case, print a single integer that represents the number of Super Subarrays in a, on a single line.
Example
Input
2
5
1 2 3 4 5
5
2 3 4 3 6
Output
6
6
In this problem, subarray is defined as non-empty sequence of consecutive elements.
We define a subarray as Super Subarray if the summation of all elements in the subarray is divisible by each element in it.
Given an array a of size n, print the number of Super Subarrays in a.
The first line of the input contains a single integer T (1 ≤ T ≤ 100), the number of test cases.
The first line of each test case contains one integer n (1 ≤ n ≤ 2000), the length of array a.
The second line of each test case contains the sequence of elements of the arraya1, a2, ..., an (1 ≤ ai ≤ 109), ai is the i-th element of the array a.
For each test case, print a single integer that represents the number of Super Subarrays in a, on a single line.
2 5 1 2 3 4 5 5 2 3 4 3 6
6 6
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
const int MX = 2e3 + 5;
const int mod = 1e9 + 7;
const int INF = 2e9 + 5;
const LL maxn = 2000*1e9;
LL a[MX], sum[MX];
LL gcd(LL a, LL b){
return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a, LL b){
return a/gcd(a, b)*b;
}
int main(){
int t, n;
scanf("%d", &t);
while(t--){
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%I64d", &a[i]);
}
sum[0] = 0;
for(int i = 1; i <= n; i++){
sum[i] = sum[i-1] + a[i];
}
LL ans = 0;
for(int i = 1; i <= n; i++){
LL tmp = a[i];
for(int j = i; j <= n; j++){
tmp = lcm(tmp, a[j]);
if(tmp > maxn) break;
if((sum[j] - sum[i-1]) % tmp == 0) ans++;
}
}
printf("%I64d\n", ans);
}
return 0;
}
In this problem, subarray is defined as non-empty sequence of consecutive elements.
We define a subarray as Super Subarray if the summation of all elements in the subarray is divisible by each element in it.
Given an array a of size n, print the number of Super Subarrays in a.
The first line of the input contains a single integer T (1 ≤ T ≤ 100), the number of test cases.
The first line of each test case contains one integer n (1 ≤ n ≤ 2000), the length of array a.
The second line of each test case contains the sequence of elements of the arraya1, a2, ..., an (1 ≤ ai ≤ 109), ai is the i-th element of the array a.
For each test case, print a single integer that represents the number of Super Subarrays in a, on a single line.
2 5 1 2 3 4 5 5 2 3 4 3 6
6 6