Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #define int long long int
- #define pb push_back
- #define ff first
- #define ss second
- const int mod = 1e9 + 7;
- const int n = 100002;
- signed main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- vector<int> sp(n,0), nod(n,1);
- for(int i = 0; i < n; i++){
- sp[i] = i;
- }
- for(int i = 2; i < n; i++){
- if(sp[i] == i){
- for(int j = i*i; j < n; j+=i){
- if(sp[j] == j){
- sp[j] = i;
- }
- }
- }
- }
- for(int i = 2; i < n; i++){
- int d = 1;
- int num = i;
- while(num != 1){
- int cnt = 0;
- int x = sp[num];
- while(num%x == 0){
- cnt++;
- num/=x;
- }
- d*=(cnt+1);
- }
- nod[i] = d;
- }
- nod[0] = 0;
- for(int i = 1; i < n; i++){
- nod[i]+=nod[i-1];
- }
- int q;
- cin>>q;
- while(q--){
- int l,r;
- cin>>l>>r;
- //cout<<1<<endl;
- cout<<nod[r]-nod[l-1]<<endl;
- //cout<<2<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement