Count Substrings

 
Problem code: CSUB
 
 

All submissions for this problem are available.

Read problems statements in Mandarin Chinese and Russian.

Given a string S consisting of only 1s and 0s, find the number of substrings which start and end both in 1.

In this problem, a substring is defined as a sequence of continuous characters Si, Si+1, ..., Sj where 1 ≤ i ≤ j ≤ N.

Input

First line contains T, the number of testcases. Each testcase consists of N(the length of string) in one line and string in second line.

Output

For each testcase, print the required answer in one line.

Constraints

  • 1T105
  • 1N105
  • Sum of N over all testcases ≤ 105

Example

Input:
2
4
1111
5
10001 Output:
10
3

存在任意两个数 gcd = 1 必然为n , 否则为 -1

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue> using namespace std;
const int N = ;
int n , m , e[N] , ans ;
inline int gcd( int a , int b ) { return b == ? a : gcd(b,a%b); }
int Run() {
scanf("%d",&n);
for( int i = ; i < n ; ++i ) scanf("%d",&e[i]);
sort( e , e + n );
for( int i = ; i < n ; ++i ) if( gcd(e[],e[i]) == ) {
return n;
}
return -;
}
int main()
{
#ifdef LOCAL
freopen("in","r",stdin);
#endif
ios::sync_with_stdio();
int _ , cas = ;
scanf("%d",&_);
while(_--) printf("%d\n",Run());
}

CodeChef Count Substrings的更多相关文章

  1. 【LeetCode】1180. Count Substrings with Only One Distinct Letter 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 组合数 日期 题目地址:https://leetcod ...

  2. scau 2015寒假训练

    并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...

  3. nodejs api 中文文档

    文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...

  4. CF451D Count Good Substrings (DP)

    Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...

  5. [LeetCode] Count Binary Substrings 统计二进制子字符串

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

  6. [Swift]LeetCode696. 计数二进制子串 | Count Binary Substrings

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

  7. LeetCode 696 Count Binary Substrings 解题报告

    题目要求 Give a string s, count the number of non-empty (contiguous) substrings that have the same numbe ...

  8. 696. Count Binary Substrings

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

  9. [LeetCode&Python] Problem 696. Count Binary Substrings

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

随机推荐

  1. 查看Xcode里的描述文件

    iOS应用打包离不开描述文件,也就是mobileprovision文件. 一般我们的操作是双击,Xcode就会运行该文件.但是具体文件里是什么,Xcode又是否真的加载了该文件?文件里又描述了什么呢? ...

  2. 关于conda-新手必读

    一.管理conda 通过anaconda来安装python及python包,让你不必关心系统是否安装了一些依赖,如zlib等等,anaconda已经集成了这些依赖,可以方便的安装python 下载请点 ...

  3. 一、Vs2019扩展多了 导航到反编译的源码中运行

    一.导航到反编译的源码中运行

  4. MYSQL学习笔记——常用语句

    1.检索数据 1.1.检索单个列:SELECT prod_name FROM products; 1.2.检索多个列:SELECT prod_id, prod_name, prod_price FRO ...

  5. 理解Promise (4)

    then 方法必须 返回一个新的promise promise2 = promise1.then(onFulfilled, onRejected); 新的Promise 必须返回传递两个方法  onF ...

  6. php io

    1.获取目录下文件,不包括子目录 //获取某目录下所有文件.目录名(不包括子目录下文件.目录名) $handler = opendir($dir); while (($filename = readd ...

  7. selenium 自动化的坑(4)

    今天要讲的坑是....输入框有请求的. 问题是这样的,我们公司的业务有些输入框选项是联想的,这些联想都会发送请求,怎么办呢? 先 正常输入,然后强制等待几秒,最好多等会,谁知道第三方会不会有问题,这里 ...

  8. Dubbo学习-3-管理控制台搭建

    dubbo 2.6.x 的dubbo-admin管理控制台搭建 1.下载源码:https://github.com/apache/incubator-dubbo-ops 打开后切换到master分支 ...

  9. centos6.5安装nginx1.16.0

    参考:   centos7 编译安装nginx1.16.0( 完整版 ) https://blog.csdn.net/weixin_37773766/article/details/80290939  ...

  10. 【Java】JSONObject学习

    介绍 JSONObject只是一种数据结构,可以理解为JSON格式的数据结构(key-value 结构),可以使用put方法给json对象添加元素.JSONObject可以很方便的转换成字符串,也可以 ...