classSolution { public: vector<bool> prefixesDivBy5(vector<int>& A){ vector<bool> result; int sum = 0; for (int i = 0; i < A.size(); ++i) { sum = sum * 2 + A[i]; sum = sum % 5; if (sum == 0) { result.push_back(true); } else { result.push_back(false); } } return result; } };
intmain(){ vector<int> A = {0, 1, 1}; vector<bool> result = Solution().prefixesDivBy5(A); for (int i = 0; i < result.size(); i++) { std::cout << result[i]; } return0; }