fork download
  1. #include <iostream>
  2.  
  3. int countDivisibles(int M, int N, int A, int B) {
  4. int count = 0;
  5. for (int i = M; i <= N; ++i) {
  6. if (i % A == 0 || i % B == 0) {
  7. ++count;
  8. }
  9. }
  10. return count;
  11. }
  12.  
  13. int main() {
  14. int M, N, A, B;
  15. int t; std::cin >> t;
  16. while (t--) {
  17. std::cin >> M >> N >> A >> B;
  18. int result = countDivisibles(M, N, A, B);
  19. std::cout << result << std::endl;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5276KB
stdin
2
5 11 4 6
3 1000 5 9
stdout
2
289