logo AlgoBeat OnlineJudge
登录 注册

#216759. [GKS 2020 #C] Perfect Subarray

内存限制:1024 MiB 时间限制:10000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Cristobal has an array of (possibly negative) integers. The i-th integer in his array is . A contiguous non-empty subarray of Cristobal's array is perfect if its total sum is a perfect square. A perfect square is a number that is the product of a non-negative integer with itself. For example, the first five perfect squares are , , , and .

How many subarrays are perfect? Two subarrays are different if they start or end at different indices in the array, even if the subarrays contain the same values in the same order.

输入格式

The first line of the input gives the number of test cases, . test cases follow. The first line of each test case contains the integer . The second line contains integers describing Cristobal's array. The i-th integer is .

输出格式

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the number of perfect subarrays.

样例

样例输入 1

3
3
2 2 6
5
30 30 9 1 30
4
4 0 0 16

样例输出 1

Case #1: 1
Case #2: 3
Case #3: 9

数据范围与提示

In sample case #1, there is one perfect subarray: [2 2] whose sum is .

In sample case #2, there are three perfect subarrays:

  • [], whose total sum is .
  • [], whose total sum is .
  • [], whose total sum is .

In sample case #3, there are nine perfect subarrays:

  • [], whose total sum is .
  • [], whose total sum is .
  • [], whose total sum is .
  • [], whose total sum is .
  • [], whose total sum is .
  • [], whose total sum is .
  • [], whose total sum is .
  • [], whose total sum is .
  • [], whose total sum is .

Note: We do not recommend using interpreted/slower languages for the test set 2 of this problem.

Limits

.

, for all .

Test Set 1

.

Test Set 2

For up to cases, .

For the remaining cases, .