Hartals
题目连结
解题
因为其输入是间隔天数,在五六不算所以用set判断,可以避免重複。
code
#include <iostream>#include <vector>#include <map>#include <set>using namespace std;int main(int argc, char const *argv[]){ int t; cin >> t; while (t--) { int d, n; cin >> d >> n; set<int> streetday; for (int i = 0; i < n; i++) { int x; cin >> x; int c = x; while (x <= d) { if (x % 7 != 6 && x % 7 != 0 && streetday.count(x) == 0) { streetday.insert(x); } x = x + c; } } cout << streetday.size() << endl; } return 0;}