fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t,l,r,k,n,rm; cin >> t;
  6. while(t--){
  7. cin >> l >> r >> k;
  8. if(k == 1){
  9. cout << r-l+1 << endl;
  10. continue;
  11. }
  12.  
  13. n = (l+r)/k;
  14. int cnt = 0,m_cnt = 0; //m_cnt : multiple count, rm : highest multiple of l in [l,r]
  15. for(int i=l;i<=n;i++){
  16. rm = (r/i)*i;
  17. m_cnt = (rm-i)/i+1;
  18. if(m_cnt >= k) cnt++;
  19. else break;
  20. }
  21. cout << cnt << endl;
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 2.6s 5292KB
stdin
8
3 9 2
4 9 1
7 9 2
2 10 2
154 220 2
147 294 2
998 24435 3
1 1000000000 2
stdout
2
6
0
4
0
1
7148
500000000