fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define db double
  5.  
  6. #define pii pair<int, int>
  7.  
  8. #define vi vector<int>
  9. #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
  10.  
  11. //pairs
  12. #define fs first
  13. #define se second
  14.  
  15. //vectors
  16. #define pb push_back
  17. #define pf push_front
  18.  
  19. //loops
  20. #define FOR(i, a, b) for(int i=(int)a;i<=(int)b;++i)
  21. #define ROF(i, a, b) for(int i=(int)a;i>=(int)b;i--)
  22. #define rep(a, x) for(auto& a : x)
  23. #define cc '\n'
  24.  
  25. //file
  26. #define file(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
  27. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  28.  
  29. using namespace std;
  30.  
  31. const int maxn = 5*1e3+7;
  32. const ll INF = 1e6;
  33.  
  34. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
  35. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. ll F[INF+1];
  37. ll s[7] = {2,3,5,7,11,13,17};
  38. map <ll, vector<ll>>MP;
  39. void init() {
  40. for (int i = 1; i <= INF; i++) F[i] = 1;
  41.  
  42. for( auto p: s){
  43. if (F[p] == 1) {
  44. for (int j = p; j <= INF; j += p) {
  45. F[j] *= p;
  46. MP[F[j]].pb(j);
  47. }
  48. }
  49. }
  50. }
  51.  
  52. void solve()
  53. {
  54. ll a, b; cin >> a >> b;
  55. map <ll, ll > mp;
  56. for(ll i = a; i<= b; i++) {
  57. mp[F[i]]++;
  58. }
  59. ll res = 0;
  60. for(auto &k : mp) {
  61. ll n = k.second;
  62. res += n*(n-1) / 2;
  63. }
  64. cout << res << cc;
  65. }
  66.  
  67. int main() {
  68. IOS;
  69. file("PRIME");
  70.  
  71. init();
  72. int T; cin >> T;
  73. while(T--) {
  74. solve();
  75. }
  76. cerr << "Time : " << TIME << " ";
  77. }
Success #stdin #stdout #stderr 0.02s 23976KB
stdin
2
1 5
1 10
stdout
1
4
stderr
Time : 0.020119