QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100

#18573. Amazing Divisibility

統計

夕阳西下。Teddy 坐在 127 路公交车上,堵在路中。闲极无聊的他已经想出了如何通过摆弄车票上的数字来凑出 100。他注意到,如果把公交车的线路号后面接上他出生的年份 1997,得到的数字可以被 7 整除。 “嘿!”,Teddy 心想,并在公交车号后面写下了 12,因为那天是 12 号。他又得到了一个能被 7 整除的数。这个傍晚开始变得有趣起来。最后,他在他出生年份的后面写下了当天的日期。

“巧合?我看没那么简单!”,Teddy 感到惊奇,并冲下公交车,以最快的速度跑回家,想要写一个程序来评估他所得到结果的概率。

帮助 Teddy 编写一个程序,从给定的集合中找出有多少种选择一对数字 $(a_i, a_j)$(其中 $i \neq j$)的方法,使得将第二个数字 $a_j$ 拼接在第一个数字 $a_i$ 之后得到的整数能被 7 整除。

输入格式

第一行包含一个整数 $N$,表示数字的个数($2 \le N \le 10^5$)。

第二行包含 $N$ 个空格分隔的互不相同的整数 $a_i$($1 \le i \le N$,$1 \le a_i \le 10^9$)。

输出格式

输出一个整数,表示从给定集合中选择一对数字 $(a_i, a_j)$(其中 $i \neq j$)的方法数,使得将第二个数字 $a_j$ 拼接在第一个数字 $a_i$ 之后得到的整数能被 7 整除。

样例

输入样例 1

3
127 1996 12

输出样例 1

4

输入样例 2

4
11 2 1 12

输出样例 2

4

说明

在第一个样例中,这三个数总共可以组成 6 对。如果将数字 1996 写在 12 后面,得到的数字是 $121996 = 7 \times 17428$。其余三个满足条件的数对已在题目背景中提及。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.