Submission #8427

# Submission time Handle Problem Language Result Execution time Memory
8427 2014-09-13T18:25:43 Z tncks0121 Xtreme gcd sum (kriii2_X) C++
0 / 4
4000 ms 1088 KB
#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
1 Correct 68 ms 1088 KB Output is correct
2 Correct 68 ms 1088 KB Output is correct
3 Correct 80 ms 1088 KB Output is correct
4 Correct 1012 ms 1088 KB Output is correct
5 Correct 912 ms 1088 KB Output is correct
6 Correct 804 ms 1088 KB Output is correct
7 Correct 256 ms 1088 KB Output is correct
8 Correct 300 ms 1088 KB Output is correct
9 Correct 336 ms 1088 KB Output is correct
10 Correct 472 ms 1088 KB Output is correct
11 Execution timed out 4000 ms 1084 KB Program timed out
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -