标签:inf pac code cin mic nbu 幸运 line space
给出n个数和一个数b 问这n个数中是否存在一个数加上b之后能被7整除 如果存在的话 即是幸运的
由(a + b) % c = a % c + b % c可知 先用b对7求余 再用n个数分别对7求余 如果这n个数%7的值加上b等于7或者b和这n个数%7的值都为0 就满足题意了
AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned long long ull; 5 6 namespace io { 7 const int SIZE = 1e7 + 10; 8 char inbuff[SIZE]; 9 char *l, *r; 10 inline void init() { 11 l = inbuff; 12 r = inbuff + fread(inbuff, 1, SIZE, stdin); 13 } 14 inline char gc() { 15 if (l == r) init(); 16 return (l != r) ? *(l++) : EOF; 17 } 18 void read(int &x) { 19 x = 0; char ch = gc(); 20 while(!isdigit(ch)) ch = gc(); 21 while(isdigit(ch)) x = x * 10 + ch - ‘0‘, ch = gc(); 22 } 23 } using io::read; 24 25 int main(){ 26 int t; 27 scanf("%d", &t); 28 int n, b; 29 int x; 30 bool flag; 31 while (t--){ 32 scanf("%d%d", &n, &b); 33 b = b % 7; 34 flag = false; 35 for (int i = 0; i < n; i++){ 36 cin>>x; 37 x = x % 7; 38 if (x + b == 7 || (!x && !b)) flag = true; 39 } 40 if (flag) cout<<"Yes"<<endl; 41 else cout<<"No"<<endl; 42 } 43 return 0; 44 }
标签:inf pac code cin mic nbu 幸运 line space
原文地址:https://www.cnblogs.com/Misuchii/p/10969714.html