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 array a1, 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 题意:给出了n个数字组成的序列,问你在这个序列中,有多少个子序列满足这样一个条件:在这一个子序列中所有元素的和能够整除这个子序列中的每一个元素。拿第一个样例拿第二个样例2 3 4 3 6来说,首先,每一个数字本身都是符合条件的,2这个数字的和可以整除2,3可以整除3......除此之外,还有一个满足条件的序列是2 3 4 3:2+3+4+3=12,12可以整除2,3,4。 题解:这题的解法第一反应都是暴力求解,遍历每一个子序列,看是否满足条件,但不用说肯定超时。正确的做法是通过记录前缀和来求每一个子序列的和(这个应该都想得到),然后要知道,一个数可以整除一些数,那这个数一定可以整除这些数的最小公倍数,反之亦然。所以我们只需要求出每个序列所有数字的的最小公倍数即可判断是否满足要求。
接下来再讲一下n个数的最小公倍数求法,首先求两个数的最小公倍数,接着再用这个公倍数去和第三个数求最小公倍数,就是三个数的最小公倍数了,四个数同理,以此类推。那如何求两个数的最小公倍数呢?首先你要知道,两个互质的数(公约数只有1),他们的最小公倍数就是他们的乘积,这个应该很好理解,所以,求两个数最小公倍数的方法就是先求出他们的最大公约数,然后其中一个数除以最大公约数,这时候,这两个数就是互质的了,再将两个数相乘就是他们的最小公倍数了。
 #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#define ll long long
#define pi 3.14159265358979323846
using namespace std;
const int inf = 0x3f3f3f3f;
const ll mod = ;
const ll maxn = *10e9;
ll gcd(ll a,ll b)//求最大公约数
{
return b== ? a : gcd(b,a%b);
} ll lcm(ll a,ll b)//求最小公倍数
{
return a/gcd(a,b)*b;
} int main()
{
ll t,n,a[],sum[];
cin>>t;
while(t--)
{
scanf("%lld",&n);
sum[] = ;
for(int i=; i<=n; ++i)
{
scanf("%lld",&a[i]);
sum[i] = sum[i-] + a[i];//求前缀和
}
ll ans=;
for(int i=; i<=n; ++i)
{
ll temp = a[i];//初始状态一个数的最小公倍数就是本身
for(int j=i; j<=n; ++j)
{
temp = lcm(temp,a[j]);//求子序列的最小公倍数
if(temp > maxn) break;
//减枝,公倍数超过此题的数据范围,直接break,因为每加一个数,公倍数只会增加或不变,所以后面都可以不用考虑了
if((sum[j] - sum[i-]) % temp == )//满足条件,ans++;
ans++;
}
}
printf("%lld\n",ans);
}
return ;
}

Gym - 101498G(Super Subarray )的更多相关文章

  1. Leetcode之动态规划(DP)专题-53. 最大子序和(Maximum Subarray)

    Leetcode之动态规划(DP)专题-53. 最大子序和(Maximum Subarray) 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. ...

  2. Gym Class(拓扑排序)

    Gym Class Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  3. LPC(Low Pin Count) 与SIO(Super IO)

    记录bios学习的点点滴滴,虽然已经学了很长时间才发出来,但就当是温故而知新吧,由于水平有限,难免存在错误,望指正,同时感谢CSDN提供的平台. 1.LPC 定义:​ Intel所定义的PC接口,将以 ...

  4. C#LeetCode刷题之#53-最大子序和(Maximum Subarray)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4012 访问. 给定一个整数数组 nums ,找到一个具有最大和的 ...

  5. C - Line-line Intersection Gym - 102220C(线段相交)

    There are n lines l1,l2,…,ln on the 2D-plane. Staring at these lines, Calabash is wondering how many ...

  6. 文件类似的推理 -- 超级本征值(super feature)

         基于内容的变长分块(CDC)技术,能够用来对文件进行变长分块.而后用来进行反复性检測,广泛用于去重系统中.后来又出现了对相似数据块进行delta压缩,进一步节省存储开销. 所以就须要一种高效 ...

  7. Masquerade strikes back Gym - 101911D(补题) 数学

    https://vjudge.net/problem/Gym-101911D 具体思路: 对于每一个数,假设当前的数是10 分解 4次,首先 1 10 这是一对,然后下一次就记录 10 1,这样的话直 ...

  8. HDU4417 (Super Mario)

    题目链接:传送门 题目大意:一个大小为 n 的数组,m组询问,每组询问[x,y]内<=v的数的数量. 题目思路:主席树(注意询问时数组下标越界问题) #include <iostream& ...

  9. Gym - 101194F(后缀数组)

    Mr. Panda and Fantastic Beasts 题意 给出若干个字符串,找到一个最短的字典序最小的字符串且仅是第一个字符串的子串. 分析 对于这种多个字符串.重复的子串问题一般都要连接字 ...

随机推荐

  1. lunix,命令集锦

    1. ls命令 ls命令是列出目录内容(List Directory Contents)的意思.运行它就是列出文件夹里的内容,可能是文件也可能是文件夹. ? 1 2 3 4 5 6 7 root@te ...

  2. Tkinter Radiobutton

    Python GUI - Tkinter Radiobutton: 这个小部件实现了多项选择按钮,这是一种方式向用户提供许多可能的选择,让用户选择只是其中之一.   这个小部件实现了多项选择按钮,这是 ...

  3. Newtonsoft.Json(Json.Net)学习

    转自原文 Newtonsoft.Json(Json.Net)学习笔记 Newtonsoft.Json,一款.NET中开源的Json序列化和反序列化类库.软件下载地址: http://www.newto ...

  4. RTTI(一) 枚举

    SetEnumProp void __fastcall TForm2::Button1Click(TObject *Sender) { //Getting the current color of t ...

  5. js调用activeX插件 报异常:TypeError:对象不支持 属性方法

    部署之后的js网页如果调用没有签名的 ocx/dll 插件的话会报异常:TypeError:对象不支持 “init” 属性方法 (init为插件公开的方法) 但是如果写一个htm本地文件去调用插件,和 ...

  6. Solo and Mute

    [Solo and Mute ] Muting means a transition will be disabled. Soloed transtions are enabled and with ...

  7. 实现把C语言编译成java字节码的编译器 一个将C语言编译成java字节码的实例

  8. 【FZU2178】礼物分配

    题意 在双胞胎兄弟Eric与R.W的生日会上,他们共收到了N个礼物,生日过后他们决定分配这N个礼物(numv+numw=N).对于每个礼物他们俩有着各自心中的价值vi和wi,他们要求各自分到的礼物数目 ...

  9. devcloud

    zone名字:devcloud 外网dns:8.8.8.8 内网dns:10.0.2.3   提供点名称:devcloud   cs bug问题:https://issues.apache.org/j ...

  10. 2-字符串模拟- URL映射

    问题描述 试题编号: 201803-3 试题名称: URL映射 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 URL 映射是诸如 Django.Ruby on Rails 等 ...