답안 #16709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16709 2015-09-08T08:55:04 Z gs14004 Xtreme gcd sum (kriii2_X) C++14
0 / 4
667 ms 262144 KB
#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 che[1000005];
int moebius[1000005];
int n, a[10005], b[10005], rng[10005];
lint cnt[1000005];

lint mod_inv(int x, int p){
	lint ret = 1, piv = x;
	while(p){
		if(p&1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret;
}

int maxp;

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;
	}
}

vector<int> change[1000005];

int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		scanf("%d %d",&a[i], &b[i]);
	}
	maxp = *min_element(b, b+n);
	get_moebius();
	lint curr = 1;
	for(int i=0; i<n; i++){
		rng[i] = 1;
		change[1].push_back(i);
	}
	for(int i=1; i<=maxp; i++){
		for(auto &j : change[i]){
			rng[j] = b[j] / i - (a[j] - 1) / i;
			int T = b[j] / i - 1;
			int s = (b[j] + T + 1) / (T + 1);
			change[s].push_back(j);
			T = (a[j] - 1) / i - 1;
			if(T != -1){
				int s = (a[j] + T) / (T + 1);
				change[s].push_back(j);
			}
		}
		lint curr = 1;
		for(int i=0; i<n; i++){
			curr *= rng[i];
			curr %= mod;
		}
		cnt[i] = curr;
	}
	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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 72996 KB Output is correct
2 Correct 17 ms 42452 KB Output is correct
3 Correct 133 ms 61016 KB Output is correct
4 Correct 18 ms 42372 KB Output is correct
5 Correct 69 ms 55412 KB Output is correct
6 Correct 22 ms 44568 KB Output is correct
7 Correct 16 ms 42120 KB Output is correct
8 Correct 8 ms 42492 KB Output is correct
9 Correct 18 ms 42336 KB Output is correct
10 Correct 10 ms 42640 KB Output is correct
11 Memory limit exceeded 667 ms 262144 KB Memory limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -