Nezzar's favorite digit among 1,…,91,…,9 is dd. He calls a positive integer lucky if dd occurs at least once in its decimal representation.
Given qq integers a1,a2,…,aqa1,a2,…,aq, for each 1≤i≤q1≤i≤q Nezzar would like to know if aiai can be equal to a sum of several (one or more) lucky numbers.
Input
The first line contains a single integer tt (1≤t≤91≤t≤9) — the number of test cases.
The first line of each test case contains two integers qq and dd (1≤q≤1041≤q≤104, 1≤d≤91≤d≤9).
The second line of each test case contains qq integers a1,a2,…,aqa1,a2,…,aq (1≤ai≤1091≤ai≤109).
Output
For each integer in each test case, print "YES" in a single line if aiai can be equal to a sum of lucky numbers. Otherwise, print "NO".
You can print letters in any case (upper or lower).
选择1~9作为最喜欢的数d,一个十进制数中若d至少出现了一次,则这个数是幸运数字。给q个整数a1,a2,…,aq,这些整数是否能表示为一个或一个以上的幸运数字之和?
思路:任何大于10 * d的数通过不断减去d ,都能得到d * 10 + x,是一个幸运数字;如果等于10 * d,那本身就是幸运数字;如果小于10 * d,那么看看这个数字能否表示为d的倍数,或者减去若干个d后是10的倍数。
#include <iostream>
#include <cstring>
#define int long long
#define N 1000005
#define INF 0x3f3f3f3f
using namespace std;
int ans=0;
void solve(int q,int d)
{
bool flag=false;
if(q>=d*10) cout<<"YES"<<endl;
else{
while(q>0)
{
if(q%10==d){
flag=true;
break;
}
q-=d;
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
signed main()
{
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
while(n--)
{
int x;
cin>>x;
solve(x,m);
}
}
return 0;
}