fork download
  1. /*
  2.   Author: Anas
  3.   Date: 15-12-2024
  4.   Time: 22:50:54
  5.   File: E_Insane_Problem.cpp
  6. */
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9.  
  10. using ll = long long;
  11.  
  12. int main() {
  13. ios::sync_with_stdio(false);
  14. cin.tie(NULL);
  15.  
  16. ll test = 1;
  17. cin >> test;
  18.  
  19. auto Anas = [&]() {
  20.  
  21. int k, l1, r1, l2, r2;
  22. cin >> k >> l1 >> r1 >> l2 >> r2;
  23.  
  24. vector<ll> maxK;
  25. for (int i=0; i < 31; i++) {
  26. ll ans=pow(k,i);
  27. if(ans > r2){
  28. break;
  29. }
  30. maxK.push_back(ans);
  31. }
  32. int cnt=0;
  33. for (auto i:maxK){
  34. for (int j = l2;j <= r2; j++){
  35. if( j % i == 0){
  36. int ans=j/i;
  37. if(ans>=l1 and ans<=r1){
  38. cnt++;
  39. }
  40. }
  41. if(i > j){
  42. break;
  43. }
  44. }
  45. }
  46.  
  47. cout<<cnt<<"\n";
  48.  
  49. };
  50.  
  51. while (test--) {
  52. Anas();
  53. }
  54.  
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
0