QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#15819. Counterfeit Money

統計

ICPC 王国的纸币具有防伪措施。每张纸币都有一个唯一的序列号,且该序列号必须能被 13 整除。换句话说,如果序列号不能被 13 整除,那么这张纸币就是伪钞。为了验证一个数是否能被 13 整除,我们可以直接用该数除以 13。不过,还有另一种方法:

将给定的十进制数的数字从右向左每三位分成一组。将每一组看作一个三位数。然后,从最右边的一组开始,对这些三位数交替进行减法和加法运算,得到最终结果。如果结果能被 13 整除,则原数能被 13 整除。否则,原数不能被 13 整除。

例如,对于数字 123,456,789,如果我们从最右边的 3 位数开始交替进行减法和加法运算,得到 $789 - 456 + 123 = 456$。由于 456 不能被 13 整除,因此原数 123,456,789 不能被 13 整除。

再举一个例子,对于数字 593,825,856,如果我们从最右边的 3 位数开始交替进行减法和加法运算,得到 $856 - 825 + 593 = 624$。由于 624 能被 13 整除($624 = 13 \times 48$),因此原数 593,825,856 能被 13 整除。

基于上述方法,编写一个程序来验证纸币是否为伪钞。

输入格式

输入包含多个测试用例。第一行表示测试用例的数量 $t$。接下来的 $t$ 行,每行包含一个正整数。给定的数字最多可包含 1000 位。

输出格式

对于每个输入的数字,输出应用上述交替加减法后得到的计算结果的绝对值。然后在同一行输出 “YES”(如果原数能被 13 整除)或 “NO”(如果不能)。计算结果与 YES/NO 之间用空格隔开。

数据范围

  • $1 \le t \le 1000$。
  • 每个输入的数字最多可包含 1000 位。

样例

输入 1

2
123456789
593825856

输出 1

456 NO
624 YES

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.