当前位置:   article > 正文

Codeforces Round #698 (Div. 2), problem: (B) Nezzar and Lucky Number_b. broken keyboardtime limit per test1 secondmemor

b. broken keyboardtime limit per test1 secondmemory limit per test512 megaby

B. Nezzar and Lucky Number
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
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;
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int main() {
  FAST;
  int T;
    cin >> T;
    
    while (T--) {
        int n, d;
        cin >> n >> d;
        for (int i = 1;i <= n; ++i) {
            int x; 
            cin >> x;
            bool flag=false;
            for (int j = 0;j <= 100; ++j) {
                
                if (j*10 <= x) {
                    int t = x - j * 10;
                    if (t % d == 0) {
                        if (t/d >= 1) flag=true;
                    }
                }
            }
            if (flag) {
                cout << "YES" << endl;
                continue;
            }
            if (x % d == 0 || x >= d*10) 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/72378
推荐阅读
相关标签
  

闽ICP备14008679号