ZOJ--Lucky 7

该博客主要介绍了一个编程问题,即给定一个正整数序列和一个正整数,判断序列中是否存在一个数,使得它与给定整数之和能被7整除。程序通过遍历序列并检查条件来解决此问题。示例测试用例解释了不同情况下的输出。

Lucky 7

Time Limit: 1000 msMemory Limit: 65536 KB

BaoBao has just found a positive integer sequence a_1, a_2, \dots, a_n of length n from his left pocket and another positive integer b from his right pocket. As number 7 is BaoBao's favorite number, he considers a positive integer x lucky if x is divisible by 7. He now wants to select an integer a​k​​ from the sequence such that (a​k​​+b) 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 n and b (1≤n,b≤100), indicating the length of the sequence and the positive integer in BaoBao's right pocket.

The second line contains n positive integers a_1, a_2, \dots, a_n (1≤a​i​​≤100), 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".

Author: WENG, Caizhi

 

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	
	int T,n,x,y;
	cin>>T;
	while(T--)
	{
		cin>>n;
		cin>>x;
		int f=0;
		
		for(int i=1;i<=n;i++)
		{
			cin>>y;
			if((x+y)%7==0&&(f==0))
			{
				f=1;
			}
			
		}
		
		if(f==1)
		{
			cout<<"Yes"<<endl;
		}
		else
		cout<<"No"<<endl;
		
	}
	
	return 0;
}

 

 

 

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值