This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
int n, a[100], b[100];
int gcd (int a, int b) {
return b ? gcd(b, a%b) : a;
}
ll sum = 0, prod[100];
const ll MOD = 1000000007;
void solve (int x, int g) {
if(x > n || g == 1) {
sum += g * prod[x];
if(sum >= MOD) sum -= MOD;
return;
}
for(int t = a[x]; t <= b[x]; t++) solve(x+1, gcd(g, t));
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d%d", a+i, b+i);
prod[n+1] = 1;
for(int i = n; i >= 1; i--) prod[i] = (prod[i+1] * (b[i] - a[i] + 1)) % MOD;
for(int g = a[1]; g <= b[1]; g++) solve(2, g);
printf("%lld\n", sum);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |