#include <iostream> #include <vector> using namespace std; int main() { int p, n; cin >> p >> n; int t[] = {2, 3, 5}; vector <int> puszki(p, 1); while(n--){ int a, b, c; cin >> a >> b >> c; a--; b--; c--; for(int i=a; i<=b; i++){ puszki[i] *= t[c]; } } int suma = 0; for(int i=0; i<p; i++){ if(puszki[i]%5 != 0){ if((puszki[i]%2 == 0) && (puszki[i]%3 == 0)) suma ++; } } cout << suma << "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <iostream> #include <vector> using namespace std; int main() { int p, n; cin >> p >> n; int t[] = {2, 3, 5}; vector <int> puszki(p, 1); while(n--){ int a, b, c; cin >> a >> b >> c; a--; b--; c--; for(int i=a; i<=b; i++){ puszki[i] *= t[c]; } } int suma = 0; for(int i=0; i<p; i++){ if(puszki[i]%5 != 0){ if((puszki[i]%2 == 0) && (puszki[i]%3 == 0)) suma ++; } } cout << suma << "\n"; } |