CodeForces - 1478B Nezzar and Lucky Number

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; 
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值