Advertisement
Barbie10

Untitled

Jan 23rd, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  6. #define int long long int
  7. #define pb push_back
  8. #define ff first
  9. #define ss second
  10. const int mod = 1e9 + 7;
  11. const int n = 100002;
  12.  
  13. signed main()
  14. {
  15.     ios_base::sync_with_stdio(0);
  16.     cin.tie(0);
  17.     cout.tie(0);
  18.    
  19.    
  20.     vector<int> sp(n,0), nod(n,1);
  21.     for(int i = 0; i < n; i++){
  22.         sp[i] = i;
  23.     }
  24.     for(int i = 2; i < n; i++){
  25.         if(sp[i] == i){
  26.             for(int j = i*i; j < n; j+=i){
  27.                 if(sp[j] == j){
  28.                     sp[j] = i;
  29.                 }
  30.             }
  31.         }
  32.     }
  33.    
  34.     for(int i = 2; i < n; i++){
  35.         int d = 1;
  36.         int num = i;
  37.         while(num != 1){
  38.             int cnt = 0;
  39.             int x = sp[num];
  40.             while(num%x == 0){
  41.                 cnt++;
  42.                 num/=x;  
  43.             }
  44.             d*=(cnt+1);
  45.         }
  46.         nod[i] = d;
  47.     }
  48.     nod[0] = 0;
  49.     for(int i = 1; i < n; i++){
  50.         nod[i]+=nod[i-1];
  51.     }
  52.    
  53.      
  54.     int q;
  55.     cin>>q;
  56.     while(q--){
  57.        
  58.         int l,r;
  59.         cin>>l>>r;
  60.         //cout<<1<<endl;
  61.         cout<<nod[r]-nod[l-1]<<endl;
  62.         //cout<<2<<endl;
  63.     }
  64.     return 0;
  65. }
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement