Lucky 7

BaoBao has just found a positive integer sequence  of length  from his left pocket and another positive integer  from his right pocket. As number 7 is BaoBao's favorite number, he considers a positive integer  lucky if  is divisible by 7. He now wants to select an integer  from the sequence such that  is lucky. Please tell him if it is possible.

Input

There are multiple test cases. The first line of the input is an integer  (about 100), indicating the number of test cases. For each test case:

The first line contains two integers  and  (), indicating the length of the sequence and the positive integer in BaoBao's right pocket.

The second line contains  positive integers  (), indicating the sequence.

Output

For each test case output one line. If there exists an integer  such that  and  is lucky, output "Yes" (without quotes), otherwise output "No" (without quotes).

Sample Input

4
3 7
4 5 6
3 7
4 7 6
5 2
2 5 2 5 2
4 26
100 1 2 4

Sample Output

No
Yes
Yes
Yes

Hint

For the first sample test case, as 4 + 7 = 11, 5 + 7 = 12 and 6 + 7 = 13 are all not divisible by 7, the answer is "No".

For the second sample test case, BaoBao can select a 7 from the sequence to get 7 + 7 = 14. As 14 is divisible by 7, the answer is "Yes".

For the third sample test case, BaoBao can select a 5 from the sequence to get 5 + 2 = 7. As 7 is divisible by 7, the answer is "Yes".

For the fourth sample test case, BaoBao can select a 100 from the sequence to get 100 + 26 = 126. As 126 is divisible by 7, the answer is "Yes".

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
const int maxn = 100+2;
int a[maxn];
using namespace std;
int n,b;
int main()
{
    int t,x;
    int flag;
    cin>>t;
    while(t--){
        memset(a,0,sizeof(a));
        flag = 0;
        cin>>n>>b;
        for(int i = 0;i<n;i++){
            cin>>a[i];
            a[i] += b;
        }
        for(int i = 0;i < n;i++){
            if(a[i] % 7 == 0){
                flag  = 1;
                break;
            }
        }
        if(flag == 1)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

 

发布了109 篇原创文章 · 获赞 18 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览