CF2269B.KiaKio and Squared Numbers

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kia and Kio spent the summer at the port of Mehragan, where nn lighthouses stand on the cliffs facing the dark sea.

The lighthouses of Mehragan do not give light. Every night a number is written in fire on each of them, and the sailors read their way from those numbers.

The law of the lighthouses is this: if a lighthouse shows xx tonight, then tomorrow night it shows the sum of the squares of the decimal digits of xx.

For example, a lighthouse showing 2323 will show 22+32=132^2+3^2=13 tomorrow, then 12+32=101^2+3^2=10, and then 11.

On night 00 of the season, lighthouse ii shows the number aia_i. From that night on, the law is applied once every night, forever.

Kio calls two lighthouses ii and jj in tune if there exists a night after which, forever, both of them show exactly the same number on every single night.

Kia asks: how many pairs (i,j)(i, j) with i<ji \lt j are in tune?

基亚和基奥在梅赫拉甘港度过了夏天,那里有 nn 座灯塔矗立在面向幽暗大海的悬崖上。

梅赫拉甘的灯塔并不发光。每晚,每座灯塔都会用火焰写出一个数字,水手们便依靠这些数字辨明航向。

灯塔的运行法则如下:若某座灯塔今晚显示数字 xx,则明晚它将显示 xx 的十进制各位数字的平方和。

例如,一座今晚显示 2323 的灯塔,明晚会显示 22+32=132^2+3^2=13,再下一天显示 12+32=101^2+3^2=10,接着显示 11。

在本季第 00 夜,第 ii 座灯塔显示数字 aia_i。从该夜起,上述法则每夜执行一次,并永远持续下去。

基奥将两座灯塔 ii 和 jj 称为“和谐的”,当且仅当存在某个夜晚,从此之后,在每一个夜晚,这两座灯塔都恰好显示完全相同的数字。

基亚提问:满足 i<ji \lt j 的和谐灯塔对 (i,j)(i, j) 共有多少对?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). The description of the test cases follows.

Each test case consists of two lines.

The first line of each test case contains a single integer nn (1≤n≤10001 \le n \le 1000) — the number of lighthouses.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the number shown by each lighthouse on night 00.

It is guaranteed that the sum of nn over all test cases does not exceed 10001000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是各测试用例的描述。

每个测试用例由两行组成。

每个测试用例的第一行包含一个整数 nn(1≤n≤10001 \le n \le 1000)—— 表示灯塔的数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 表示第 00 夜每个灯塔显示的数字。

保证所有测试用例的 nn 之和不超过 10001000。

输出格式

For each test case, print a single integer — the number of pairs (i,j)(i, j) with i<ji \lt j such that lighthouses ii and jj are in tune.

对于每个测试用例,输出一个整数——满足 i<ji \lt j 且灯塔 ii 与灯塔 jj 处于调谐状态的数对 (i,j)(i, j) 的个数。

输入输出样例

  • 输入#1

    4
    5
    7 4 16 4 2
    4
    1 7 10 100
    3
    4 16 37
    3
    2 20 4

    输出#1

    1
    6
    0
    1

说明/提示

In the first test case:

  • Lighthouse 11 starts at 77: 7→49→97→130→10→17 \to 49 \to 97 \to 130 \to 10 \to 1, and it stays at 11 forever.
  • Lighthouses 22 and 44 both start at 44, so they show the same number on every night.
  • Lighthouse 33 starts at 1616 and lighthouse 55 starts at 22; each of them is at a different point of the cycle Kio found, and never matches anybody.

So the only pair in tune is (2,4)(2, 4), and the answer is 11.

In the second test case, every lighthouse sooner or later reaches 11 and stays there, so all of them are pairwise in tune, which gives 66 pairs.

In the fourth test case, on night 11, lighthouse 22 shows 22+02=42^2+0^2 = 4, and lighthouse 11 shows 22=42^2 = 4. From night 11 on, they are identical forever. Lighthouse 33 starts at 44, so it is one night ahead of both of them and is in tune with neither.

在第一个测试用例中:

  • 灯塔 11 起始于 77:7→49→97→130→10→17 \to 49 \to 97 \to 130 \to 10 \to 1,此后永远停留在 11。
  • 灯塔 22 和 44 均起始于 44,因此它们在每个夜晚显示的数字都相同。
  • 灯塔 33 起始于 1616,灯塔 55 起始于 22;它们各自处于 Kio 所发现的循环中的不同位置,且永远不会与其他任何灯塔匹配。

因此,唯一一对同步的灯塔是 (2,4)(2, 4),答案为 11。

在第二个测试用例中,所有灯塔最终都会到达 11 并永远停留于该值,因此所有灯塔两两之间均同步,共产生 66 对。

在第四个测试用例中,第 11 夜时,灯塔 22 显示 22+02=42^2+0^2 = 4,灯塔 11 显示 22=42^2 = 4。从第 11 夜起,它们将永远完全一致。灯塔 33 起始于 44,因此比它们领先一个夜晚,与二者均不同步。

输入解题思路,AI测评打分。不知道怎么写?

首页