This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
int rng = 1e6;
 
int che[1000005];
int moebius[1000005];
int n, a[10005], b[10005];
lint cnt[1000005];
 
lint get(int x){
    lint ret = 1;
    for(int i=0; i<n; i++){
        ret *= b[i] / x - (a[i] - 1) / x;
        ret %= mod;
    }
    return ret;
}
 
int main(){
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        scanf("%d %d",&a[i], &b[i]);
    }
  rng = *min_element(b, b+n);
    for(int i=2; i<=rng; i++){
        for(int j=i; j<=rng; j+=i){
            if(!che[j]) che[j] = i;
        }
    }
    for(int i=1; i<=rng; i++){
        int cnt = 0, lst = -1;
        int x = i;
        while(x > 1){
            if(lst == che[x]){
                cnt = -1;
                break;
            }
            lst = che[x];
            x /= lst;
            cnt++;
        }
        if(cnt < 0) continue;
        moebius[i] = cnt % 2 ? -1 : 1;
    }
    for(int i=1; i<=rng; i++){
        cnt[i] = get(i);
    }
    lint ret = 0;
    for(int i=1; i<=rng; i++){
        for(int j=1; i*j<=rng; j++){
            ret += 1ll * i * moebius[j] * cnt[i * j] % mod;
            ret %= mod;
        }
    }
    printf("%lld",ret);
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |