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 a1,a2,…,aq, for each 1≤i≤q Nezzar would like to know if ai 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≤104, 1≤d≤9).
The second line of each test case contains q integers a1,a2,…,aq (1≤ai≤109).
Output
For each integer in each test case, print “YES” in a single line if ai can be equal to a sum of lucky numbers. Otherwise, print “NO”.
You can print letters in any case (upper or lower).
Example
inputCopy
2
3 7
24 25 27
10 7
51 52 53 54 55 56 57 58 59 60
outputCopy
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
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.
思路:
题目说幸运数数字十位或者个位为d就成立,
假设d=7,则数‘a7’(0<=a<=9)或者‘7b’(0<=b<=9)都是幸运数字。
(1)由此可以可以发现当任意一个数num=‘a7’+‘7b’=77+‘ab’,既num>=77时都输出"YES"。
(2)因为十位为7也成立,所以当num>=70时均成立。
(3)当num<70,当num可以由咯干个7加上一个‘a7’,既num=7i+‘a0’,所以(num-7i)%10==0
#include<iostream>
using namespace std;
int q,t,d,a;
int main()
{
cin >> t;
while(t --)
{
cin >> q >> d;
while(q --)
{
cin >> a;
if(a >= 10 *d)
{
cout << "YES" << endl;
continue;
}
int p = 1;
for(int i = 1; i < 10; i ++)
{
int s = a - i * d;
if( s < 0)
break;
else if(s%10 == 0)
{
p = 0;
cout << "YES" << endl;
break;
}
}
if(p)
cout << "NO" << endl;
}
}
return 0;
}