Codeforces Round 698 B 题解
Nezzar and Lucky Number
Nezzar's favorite digit among $1,…,9$ is $d$. He calls a positive integer lucky if $d$ occurs at least once in its decimal representation.
Given $q$ integers $a_1,a_2,…,a_q$, for each $1≤i≤q$ Nezzar would like to know if $a_i$ can be equal to a sum of several (one or more) lucky numbers.
Input
The first line contains a single integer $t$ ($1≤t≤9$) — the number of test cases.
The first line of each test case contains two integers $q$ and $d$ ($1≤q≤10^4$, $1≤d≤9$).
The second line of each test case contains $q$ integers $a_1,a_2,…,a_q$ ($1≤a_i≤10^9$).
Output
For each integer in each test case, print YES
in a single line if $a_i$ can be equal to a sum of lucky numbers. Otherwise, print NO
.
You can print letters in any case (upper or lower).
Example
input
1 |
|
output
1 |
|
Note
In the first test case, $24=17+7$, $27$ itself is a lucky number, $25$ cannot be equal to a sum of lucky numbers.
题目大意
对于数 $a$ ,如果在一个数的十进制描述法中存在任何的位等于 $d$ ,那么就称这个数是“幸运数”。现在给你 $q$ 组数和一个数 $d$ ,问你这 $q$ 组数是否能分别被表示成 $n$ 个“幸运数”的和 ($n >= 1$)。
分析
我至今没有理解我做法的正确性,但是凭感觉就想出来了然后提交居然还通过了。对于一个数 $n$ ,先去看它是不是幸运数,如果是就直接输出 YES
,如果不是的话,做 $n -= d$ 再去看 $n$ 是不是幸运数,再不是就接着减,直到不满足 $n-d > 0$ 。
这道题按照官方说明是一个dp题,我觉得我这么做会有被Hack的风险,用dp可能会更好一点。
AC代码
1 |
|
Codeforces Round 698 B 题解