답안 #16702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16702 2015-09-08T08:20:35 Z gs14004 Xtreme gcd sum (kriii2_X) C++14
1 / 4
4000 ms 17424 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 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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17424 KB Output is correct
2 Correct 0 ms 17424 KB Output is correct
3 Correct 0 ms 17424 KB Output is correct
4 Correct 0 ms 17424 KB Output is correct
5 Correct 0 ms 17424 KB Output is correct
6 Correct 0 ms 17424 KB Output is correct
7 Correct 0 ms 17424 KB Output is correct
8 Correct 0 ms 17424 KB Output is correct
9 Correct 0 ms 17424 KB Output is correct
10 Correct 0 ms 17424 KB Output is correct
11 Correct 249 ms 17424 KB Output is correct
12 Correct 253 ms 17424 KB Output is correct
13 Correct 254 ms 17424 KB Output is correct
14 Correct 251 ms 17424 KB Output is correct
15 Correct 269 ms 17424 KB Output is correct
16 Correct 6 ms 17424 KB Output is correct
17 Correct 5 ms 17424 KB Output is correct
18 Correct 269 ms 17424 KB Output is correct
19 Correct 88 ms 17424 KB Output is correct
20 Correct 144 ms 17424 KB Output is correct
21 Correct 31 ms 17424 KB Output is correct
22 Correct 308 ms 17424 KB Output is correct
23 Correct 310 ms 17424 KB Output is correct
24 Correct 311 ms 17424 KB Output is correct
25 Correct 304 ms 17424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17424 KB Output is correct
2 Correct 0 ms 17424 KB Output is correct
3 Correct 1 ms 17424 KB Output is correct
4 Correct 0 ms 17424 KB Output is correct
5 Correct 0 ms 17424 KB Output is correct
6 Correct 0 ms 17424 KB Output is correct
7 Correct 0 ms 17424 KB Output is correct
8 Correct 0 ms 17424 KB Output is correct
9 Correct 0 ms 17424 KB Output is correct
10 Correct 0 ms 17424 KB Output is correct
11 Execution timed out 4000 ms 17420 KB Program timed out
12 Halted 0 ms 0 KB -