zoukankan      html  css  js  c++  java
  • Codeforces Round #698 (Div. 2) B. Nezzar and Lucky Number

    B. Nezzar and Lucky Number

    点击题目可传送至原题

    今天状态太差了,唉

    题面

    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 (a_1,a_2,…,a_q), for each $1≤i≤q$1 Nezzar would like to know if (a_1) 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 (a_1,a_2,…,a_q (1≤ai≤109)).

    Output

    For each integer in each test case, print "YES" in a single line if (a_i) can be equal to a sum of lucky numbers. Otherwise, print "NO".

    You can print letters in any case (upper or lower).

    Example

    input

    2
    3 7
    24 25 27
    10 7
    51 52 53 54 55 56 57 58 59 60
    

    output

    YES
    NO
    YES
    YES
    YES
    NO
    YES
    YES
    YES
    YES
    YES
    YES
    NO
    

    Note

    In the first test case, 24=17+724=17+7, 2727 itself is a lucky number, 2525 cannot be equal to a sum of lucky numbers.

    题目分析

    题意:给你一个从1到10的数字d,再给你一组数。让你这组数里的每一个数字能否拆分为含有d的数字相加的形式

    分析

    • 当判断数字大于(10 * d)时,必定能满足要求。

      当数字大于(10 * d)的时候,你总能让拆分的两个数字的个位或百位或千位出现d。这个规律可以自行推导或者打表得到。

    • 当判断数字小于(10 * d)时,如果一个数字在减去n * 10之后能被d整除,那么必定能满足要求。

      小于(10 * d)时,一个满足条件的数字通常由(d + (10 + d) + (20 + d) ...)组成。说明满足条件的数字满足 $ m * 10 + n *d $ 的构成。所以当(m = 0)的时候,剩下的数字能被d整除,那么就满足要求。

    AC代码

    #include <bits/stdc++.h>
    using namespace std;
    #define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
    
    const int N = 100100;
    int q[N];
    int t, n, m;
    int d;
    
    inline void solve() {
        cin >> n >> d;
        for (int i = 0; i < n; i++) {
            cin >> q[i];
            if (q[i] > d * 10)
                cout << "YES" << endl;
            else {
                bool j = 0;
                while (q[i] > 0) {
                    if (q[i] % d == 0) {
                        j = 1;
                        break;
                    }
                    q[i] -= 10;
                }
                if (j)
                    cout << "YES" << endl;
                else
                    cout << "NO" << endl;
            }
        }
    }
    
    int main() {
        io;
        cin >> t;
        while (t--) {
            solve();
        }
        return 0;
    }
    
  • 相关阅读:
    java中判断图片格式并且等比例压缩图片
    如何将freemarker文件转化为html文件
    细数用anaconda安装mayavi时出现的各种问题
    利用java代码生成keyStore
    时间戳获取 天/月/日等until
    navicat连接msql Client does not support authentication protocol requested by server; consider upgrading MySQL client
    类初始化和构造器初始化的区别
    git从自己账号切换到公司的账号,剪项目失败
    求吸血鬼数(1000~10000,thinking)
    vue。js的时间的格式化
  • 原文地址:https://www.cnblogs.com/FrankOu/p/14342750.html
Copyright © 2011-2022 走看看