B. Nezzar and Lucky Number
Codeforces Round #698 (Div. 2) B
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 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
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+7, 27 itself is a lucky number, 25 cannot be equal to a sum of lucky numbers.
linkB
分析:
①当x大于等于 d*10 时,满足情况,因可从1,2,3,4,5,6,7,8,9,0里随意组合
② 若x < d*10,此时 x 为两位数,十位数可自由组合,所以只观察个位数字,若 x 的个位数字为d的倍数,x -= d ,总会得到 x % 10 == d ,否则答案为no
代码:
#include <iostream>using namespace std;int main()
{int t;cin >> t;int n,d;while(t --){cin >> n >> d;while(n --){int x;cin >> x;if(x >= d * 10) cout << "YES" << endl;else{int flag = 0;while(x >= 0){if(x % 10 != d)x -= d;else {flag = 1;cout << "YES" << endl;break;} }if(flag == 0)cout << "NO" << endl;}}}
return 0;
}
B. Nezzar and Lucky Number相关推荐
- Codeforces1478 B. Nezzar and Lucky Number(推导)
题意: 解法: 对于数x,如果x>=10*d,那么一定有解, 证明: 将x对10*d取模,分出若干个10*d之后,设余数为p, 接着将p为d取模,显然此时余数<10,将这个余数与之前的某个 ...
- 枚举 + 进制转换 --- hdu 4937 Lucky Number
Lucky Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) T ...
- hdu 4937 Lucky Number(数学题 进制转换)2014多校训练第7场
Lucky Number Time Limit: 20 ...
- lucky number
4,7是lucky number ,当一个数出现1个以上非lucky number就是我们所不需要的,问a,b间有多少个,由于数据范围只有1-1000000 int findLuckyNumber(i ...
- 九度oj 题目1380:lucky number
题目描述: 每个人有自己的lucky number,小A也一样.不过他的lucky number定义不一样.他认为一个序列中某些数出现的次数为n的话,都是他的lucky number.但是,现在这个序 ...
- UVA10909 Lucky Number题解
原文链接:http://www.algorithmist.com/index.php/User:Sweepline/UVa_10909.cpp AC的C++语言程序: /** Solution for ...
- Nearly Lucky Number
文章目录 一.Nearly Lucky Number 总结 一.Nearly Lucky Number 本题链接:Nearly Lucky Number 题目: A. Nearly Lucky Num ...
- C#,幸运数字(Lucky Number)的算法与源代码
Lucky Number不是蔡依林的歌曲名字哦. 给你的NV朋友选一个幸运数字吧. 一.幸运数字是怎么产生的? 幸运数是整数的子集.与其进行大量理论研究,不如让我们来看看得出幸运数字的过程, 以整数集 ...
- 110A.Nearly Lucky Number
110A.Nearly Lucky Number 题目 翻译 题目 输入 输出 分析 代码 题目 翻译 题目 Petya喜欢幸运数.众所周知只包含幸运数字4和7的十进制正数称为幸运数.比如说,47,7 ...
最新文章
- Python字符串常用函数详解
- 手把手教你做一辆mini平衡自行车!
- 第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波11 - 直方图处理 - 使用直方图统计量增强图像
- 文件无刷新上传(swfUpload与uploadify)
- 如何解决 IDEA 占用大量 CPU 导致的卡顿问题?这顿操作猛如虎
- java搭建线程池框架_JAVA线程池经管及分布式HADOOP调剂框架搭建
- linux系统写一个脚本,编写一个简单的linuxshell脚本
- Atitit java文件监控 WatchService 的使用 目录 1. // 处理下级多层目录	1 2. // 处理新目录	1 3. Code	2 常见问题对于 1.// 处理下级多层目
- myeclipse复制的文件代码乱码
- 模型推理速度与硬件算力
- win10键盘快捷键
- 【秀米教程5】点击动作
- 如何运营好微信公众号?如何利用微信公众号盈利?
- 前沿 | 社区问答系统及相关技术
- foo java_Java的类型参数通配符到底意味着什么? Foo和Foo ?之间的真正区别是什么?...
- php自定义函数全局声明,【phpcms-v9】phpcms-v9中自定义全局函数文件:extention.func.php...
- 关于Intriguing properties of neural networks的理解
- android 笔试题大全,2018年Android面试题大全
- 物联网毕业设计题目选题大全
- 三大顶级Linux发行版对比