fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int gcd( int a,int b){
  5. int h;
  6. for(h = a<b?a:b; h >= 1; h--){
  7. if((a%h == 0) && (b%h == 0))
  8. break;
  9. }
  10.  
  11. return h;
  12. }
  13.  
  14. int main() {
  15. int n1, n2, lcm, hcf, cnt = 0;
  16. cin >> n1 >> n2 >> hcf >> lcm;
  17.  
  18. for (int i = n1; i <= n2; i++) {
  19. //checking if the number divides the lcm completely
  20. if(lcm%i == 0){
  21. int a = hcf * lcm / i;// its other multiplier
  22.  
  23. //checking if their gcd is equal to given hcf
  24. if (a <= n2 && a >= n1) {
  25. int b = gcd(a, i);//finding their gcd
  26. if(b == hcf){
  27. int c = (i*a) / b;//finding the lcm by a*b = lcm*hcf formula and
  28. //checking
  29. if(c == lcm){
  30. cnt++;
  31. }
  32. }
  33. }
  34. }
  35. }
  36.  
  37. cout<<cnt<<endl;
  38. return 0;
  39. }
  40.  
  41.  
  42.  
Success #stdin #stdout 0s 4512KB
stdin
100 7000 12 720720
stdout
18