Description:
BaoBao has just found a positive integer sequence a1,a2,……,an 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 lucky if is divisible by 7. He now wants to select an integer ak from the sequence such that ( ak+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 T (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 a1,a2,……,an ( 1≤n≤100 ), indicating the sequence.
Output:
For each test case output one line. If there exists an integer ak such that ak∈{a1,a2,……,an} and (ak+b) 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
题目连接
直接枚举判断是否存在 (ai+b)%7==0 。
AC代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e2+5;
const double eps = 1e-5;
const double pi = asin(1.0)*2;
const double e = 2.718281828459;
int t;
int n, b;
int a;
bool flag;
int main() {
//fropen("in.txt", "r", stdin);
scanf("%d", &t);
while (t--) {
flag = 0;
scanf("%d %d", &n, &b);
for (int i = 0; i < n; ++i) {
scanf("%d", &a);
if (flag) {
continue;
}
else {
if ((a + b) % 7 == 0) {
flag = 1;
}
}
}
if (!flag) {
printf("No\n");
}
else {
printf("Yes\n");
}
}
return 0;
}