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. springmvc 使用ajx上传文件 不设置form enctype

    最近在做一个小项目 碰到这个问题 解决方案如下 1.js代码如下 获取当前form 转换为formdata ajax提交到后台 var form = $("#importForm" ...

  2. 【转】tcp_tw_recycle和tcp_timestamps导致connect失败问题

    (2012-02-01 18:40:32)     近来线上陆续出现了一些connect失败的问题,经过分析试验,最终确认和proc参数tcp_tw_recycle/tcp_timestamps相关: ...

  3. python:while 语句的使用方法

    while语句: count = 0 while True: print(count) count += 1 if count == 10: break 实例: 计算n!,若:n = 5:则:n! = ...

  4. 【290】Python 函数

    参考:Python 函数 参考:7.3 给函数参数增加元信息(增加参数的数据类型) 目录: 一.语法 二.说明 三.参数传递 四.参数 4. 1 必备参数 4.2 关键字参数 4.3 缺省参数 4.4 ...

  5. java反射对实体类取值和赋值,可以写成通过实体类获取其他元素的数据,很方便哦~~~

    项目中需要过滤前面表单页面中传过来的实体类的中的String类型变量的前后空格过滤,由于前几天看过一个其他技术博客的的java反射讲解,非常受益.于是,哈哈哈 public static <T& ...

  6. css实现图标移上图标弹跳效果

    html部分: <div class="bounce" style="width:20px;height:20px;border:1px solid red;&qu ...

  7. HTML标签及属性

    HTML 标签大全及属性  来源:http://www.cnblogs.com/Mr-liyang/p/5797976.html 基本结构标签:<HTML>,表示该文件为HTML文件< ...

  8. Unity 之 Shader 面的剔除 Cull

    面的剔除 Cull 在渲染的时候,默认情况下是只有朝向摄像机的面才会被渲染,可以告诉Unity,我想渲染哪一个朝向的面,使用Cull命令在计算体积阴影的时候会用到对Cull的操作来计算和物体相交的投影 ...

  9. Opencv3 形态学操作

    #include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...

  10. Node.js简介(转)

    目前,Node.js是在前端页面开发中十分受欢迎的,它是一套用来编写高性能网络服务器的JavaScript工具包,在本文中,将带领各位初学者介绍Node JS的基本知识,要求本文的阅读对象为有一定Ja ...