当前位置:   article > 正文

Nezzar and Lucky Number_nezzar's favorite digit among 1,\ldots,91,…,9 is d

nezzar's favorite digit among 1,\ldots,91,…,9 is dd. he calls a positive in

题目:
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.

题解:

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int q,d;
		scanf("%d %d",&q,&d);
		long long a;
		for(int i=0;i<q;i++)
		{
			scanf("%lld",&a);
			if(a>=d*10) cout<<"YES"<<endl;
			else
			{
			int s,r=0;
			long long b=a;
			while(b>0)
			{
				s=b%10;
				if(s==d)
				{
					r=1;
					break;
				}
				b/=10;
			}
			if(r) cout<<"YES"<<endl;
			else
			{
				long long sum=a;
				b=a/10;
				long long z=b*10;
				for(long long i=z;i>=10;i-=10)
				{
					if((sum-i)%d==0&&sum-i!=0)
					{
						r=1;
						break;
					}
				}
				if(r) cout<<"YES"<<endl;
				else
				{
					if(a%d==0) cout<<"YES"<<endl;
					else cout<<"NO"<<endl;
				}
			}
		}
		}
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/72390
推荐阅读
相关标签
  

闽ICP备14008679号