#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;
const int maxp = 1e6;
int che[1000005];
int moebius[1000005];
int n;
void get_moebius(){
for(int i=2; i<=maxp; i++){
for(int j=i; j<=maxp; j+=i){
if(!che[j]) che[j] = i;
}
}
for(int i=1; i<=maxp; 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;
}
}
int dx[1000005];
lint cnt[1000005];
lint inv[1000005];
int main(){
scanf("%d",&n);
for(int i=1; i<=maxp; i++){
lint ret = 1, piv = i;
int p = mod - 2;
while(p){
if(p&1) ret *= piv;
piv *= piv;
ret %= mod;
piv %= mod;
p >>= 1;
}
inv[i] = ret;
}
fill(cnt, cnt + maxp + 1, 1);
for(int i=0; i<n; i++){
int a, b;
scanf("%d %d",&a, &b);
int pos = 1, cur = -1;
int nxt_update = 1;
while(pos <= maxp){
cur = b / pos - (a - 1) / pos;
nxt_update = 1e9;
int T = b / pos - 1;
if(T >= 0){
int s = (b + T + 1) / (T + 1);
if(s > pos) nxt_update = min(nxt_update, s);
}
T = (a - 1) / pos - 1;
if(T >= 0){
int s = (a + T) / (T + 1);
if(s > pos) nxt_update = min(nxt_update, s);
}
nxt_update = min(nxt_update, maxp + 1);
if(cur == 0){
dx[pos]++;
dx[nxt_update]--;
}
else{
cnt[nxt_update] *= inv[cur];
cnt[pos] *= cur;
cnt[pos] %= mod;
cnt[nxt_update] %= mod;
}
pos = nxt_update;
}
}
for(int i=1; i<=maxp; i++){
cnt[i] *= cnt[i-1];
dx[i] += dx[i-1];
cnt[i] %= mod;
}
for(int i=1; i<=maxp; i++){
if(dx[i]) cnt[i] = 0;
}
get_moebius();
lint ret = 0;
for(int i=1; i<=maxp; i++){
for(int j=1; i*j<=maxp; j++){
ret += 1ll * i * moebius[j] * cnt[i * j] % mod;
ret %= mod;
}
}
ret += mod;
ret %= mod;
printf("%lld",ret);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
460 ms |
29064 KB |
Output is correct |
2 |
Correct |
452 ms |
29064 KB |
Output is correct |
3 |
Correct |
459 ms |
29064 KB |
Output is correct |
4 |
Correct |
478 ms |
29064 KB |
Output is correct |
5 |
Correct |
457 ms |
29064 KB |
Output is correct |
6 |
Correct |
430 ms |
29064 KB |
Output is correct |
7 |
Correct |
454 ms |
29064 KB |
Output is correct |
8 |
Correct |
457 ms |
29064 KB |
Output is correct |
9 |
Correct |
456 ms |
29064 KB |
Output is correct |
10 |
Correct |
455 ms |
29064 KB |
Output is correct |
11 |
Correct |
451 ms |
29064 KB |
Output is correct |
12 |
Correct |
461 ms |
29064 KB |
Output is correct |
13 |
Correct |
446 ms |
29064 KB |
Output is correct |
14 |
Correct |
460 ms |
29064 KB |
Output is correct |
15 |
Correct |
455 ms |
29064 KB |
Output is correct |
16 |
Correct |
451 ms |
29064 KB |
Output is correct |
17 |
Correct |
455 ms |
29064 KB |
Output is correct |
18 |
Correct |
454 ms |
29064 KB |
Output is correct |
19 |
Correct |
456 ms |
29064 KB |
Output is correct |
20 |
Correct |
453 ms |
29064 KB |
Output is correct |
21 |
Correct |
457 ms |
29064 KB |
Output is correct |
22 |
Correct |
458 ms |
29064 KB |
Output is correct |
23 |
Correct |
445 ms |
29064 KB |
Output is correct |
24 |
Correct |
461 ms |
29064 KB |
Output is correct |
25 |
Correct |
451 ms |
29064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
450 ms |
29064 KB |
Output is correct |
2 |
Correct |
453 ms |
29064 KB |
Output is correct |
3 |
Correct |
451 ms |
29064 KB |
Output is correct |
4 |
Correct |
454 ms |
29064 KB |
Output is correct |
5 |
Correct |
461 ms |
29064 KB |
Output is correct |
6 |
Correct |
456 ms |
29064 KB |
Output is correct |
7 |
Correct |
450 ms |
29064 KB |
Output is correct |
8 |
Correct |
451 ms |
29064 KB |
Output is correct |
9 |
Correct |
451 ms |
29064 KB |
Output is correct |
10 |
Correct |
454 ms |
29064 KB |
Output is correct |
11 |
Correct |
537 ms |
29064 KB |
Output is correct |
12 |
Correct |
521 ms |
29064 KB |
Output is correct |
13 |
Correct |
525 ms |
29064 KB |
Output is correct |
14 |
Correct |
521 ms |
29064 KB |
Output is correct |
15 |
Correct |
527 ms |
29064 KB |
Output is correct |
16 |
Correct |
459 ms |
29064 KB |
Output is correct |
17 |
Correct |
458 ms |
29064 KB |
Output is correct |
18 |
Correct |
757 ms |
29064 KB |
Output is correct |
19 |
Correct |
834 ms |
29064 KB |
Output is correct |
20 |
Correct |
683 ms |
29064 KB |
Output is correct |
21 |
Correct |
594 ms |
29064 KB |
Output is correct |
22 |
Correct |
1044 ms |
29064 KB |
Output is correct |
23 |
Correct |
1137 ms |
29064 KB |
Output is correct |
24 |
Correct |
946 ms |
29064 KB |
Output is correct |
25 |
Correct |
949 ms |
29064 KB |
Output is correct |