結果

問題 No.1262 グラフを作ろう!
ユーザー finefine
提出日時 2020-10-16 23:53:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 3,000 ms
コード長 1,462 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 165,064 KB
実行使用メモリ 19,244 KB
最終ジャッジ日時 2023-09-28 06:41:37
合計ジャッジ時間 21,726 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
18,980 KB
testcase_01 AC 143 ms
18,976 KB
testcase_02 AC 172 ms
18,996 KB
testcase_03 AC 170 ms
18,996 KB
testcase_04 AC 98 ms
18,988 KB
testcase_05 AC 130 ms
18,984 KB
testcase_06 AC 94 ms
19,040 KB
testcase_07 AC 97 ms
18,932 KB
testcase_08 AC 137 ms
19,036 KB
testcase_09 AC 144 ms
18,932 KB
testcase_10 AC 129 ms
19,048 KB
testcase_11 AC 141 ms
18,992 KB
testcase_12 AC 168 ms
19,052 KB
testcase_13 AC 169 ms
18,936 KB
testcase_14 AC 125 ms
18,976 KB
testcase_15 AC 131 ms
18,924 KB
testcase_16 AC 150 ms
19,004 KB
testcase_17 AC 143 ms
19,156 KB
testcase_18 AC 169 ms
18,940 KB
testcase_19 AC 100 ms
18,988 KB
testcase_20 AC 117 ms
18,988 KB
testcase_21 AC 178 ms
18,944 KB
testcase_22 AC 96 ms
18,928 KB
testcase_23 AC 138 ms
19,056 KB
testcase_24 AC 145 ms
19,048 KB
testcase_25 AC 98 ms
18,944 KB
testcase_26 AC 106 ms
19,208 KB
testcase_27 AC 122 ms
19,168 KB
testcase_28 AC 118 ms
19,084 KB
testcase_29 AC 109 ms
18,992 KB
testcase_30 AC 115 ms
19,104 KB
testcase_31 AC 182 ms
19,104 KB
testcase_32 AC 138 ms
18,940 KB
testcase_33 AC 116 ms
18,968 KB
testcase_34 AC 128 ms
18,944 KB
testcase_35 AC 164 ms
18,928 KB
testcase_36 AC 124 ms
19,000 KB
testcase_37 AC 174 ms
18,996 KB
testcase_38 AC 131 ms
19,244 KB
testcase_39 AC 206 ms
18,984 KB
testcase_40 AC 205 ms
19,076 KB
testcase_41 AC 110 ms
18,956 KB
testcase_42 AC 160 ms
18,984 KB
testcase_43 AC 123 ms
19,096 KB
testcase_44 AC 133 ms
19,104 KB
testcase_45 AC 156 ms
18,936 KB
testcase_46 AC 111 ms
19,032 KB
testcase_47 AC 148 ms
19,036 KB
testcase_48 AC 150 ms
19,048 KB
testcase_49 AC 172 ms
19,048 KB
testcase_50 AC 151 ms
19,028 KB
testcase_51 AC 149 ms
19,100 KB
testcase_52 AC 111 ms
18,956 KB
testcase_53 AC 107 ms
18,992 KB
testcase_54 AC 178 ms
19,040 KB
testcase_55 AC 153 ms
18,952 KB
testcase_56 AC 117 ms
19,116 KB
testcase_57 AC 185 ms
18,956 KB
testcase_58 AC 165 ms
18,992 KB
testcase_59 AC 116 ms
19,076 KB
testcase_60 AC 181 ms
19,040 KB
testcase_61 AC 128 ms
19,028 KB
testcase_62 AC 167 ms
18,984 KB
testcase_63 AC 174 ms
18,956 KB
testcase_64 AC 145 ms
18,940 KB
testcase_65 AC 102 ms
18,984 KB
testcase_66 AC 125 ms
18,992 KB
testcase_67 AC 114 ms
18,976 KB
testcase_68 AC 102 ms
18,936 KB
testcase_69 AC 115 ms
18,980 KB
testcase_70 AC 145 ms
18,940 KB
testcase_71 AC 141 ms
19,004 KB
testcase_72 AC 157 ms
19,080 KB
testcase_73 AC 172 ms
19,044 KB
testcase_74 AC 161 ms
18,952 KB
testcase_75 AC 149 ms
19,024 KB
testcase_76 AC 139 ms
19,004 KB
testcase_77 AC 158 ms
18,992 KB
testcase_78 AC 148 ms
18,924 KB
testcase_79 AC 167 ms
18,948 KB
testcase_80 AC 142 ms
18,940 KB
testcase_81 AC 159 ms
19,168 KB
testcase_82 AC 176 ms
18,928 KB
testcase_83 AC 142 ms
18,984 KB
testcase_84 AC 141 ms
19,168 KB
testcase_85 AC 173 ms
18,972 KB
testcase_86 AC 159 ms
18,996 KB
testcase_87 AC 174 ms
18,980 KB
testcase_88 AC 161 ms
19,036 KB
testcase_89 AC 140 ms
18,928 KB
testcase_90 AC 178 ms
19,000 KB
testcase_91 AC 168 ms
18,984 KB
testcase_92 AC 169 ms
19,076 KB
testcase_93 AC 179 ms
19,040 KB
testcase_94 AC 166 ms
18,984 KB
testcase_95 AC 168 ms
19,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\n';
  
#define MAX 1000001 
  
// phi[i] stores euler totient function for i 
// result[j] stores result for value j 
long long phi[MAX], result[MAX]; 
  
// Precomputation of phi[] numbers. Refer below link 
// for details : https://goo.gl/LUqdtY 
void computeTotient() 
{ 
    // Refer https://goo.gl/LUqdtY 
    phi[1] = 1; 
    for (int i=2; i<MAX; i++) 
    { 
        if (!phi[i]) 
        { 
            phi[i] = i-1; 
            for (int j = (i<<1); j<MAX; j+=i) 
            { 
                if (!phi[j]) 
                    phi[j] = j; 
  
                phi[j] = (phi[j]/i)*(i-1); 
            } 
        } 
    } 
}

// Precomputes result for all numbers till MAX 
void sumOfGcdPairs() 
{ 
    // Precompute all phi value 
    computeTotient(); 
  
    for (int i=1; i<MAX; ++i) 
    { 
        // Iterate throght all the divisors 
        // of i. 
        for (int j=2; i*j<MAX; ++j) 
            result[i*j] += i*phi[j]; 
    } 
  
    // Add summation of previous calculated sum 
    for (int i=2; i<MAX; i++) 
        result[i] += result[i-1]; 
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    sumOfGcdPairs();

    ll ans = 0;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        ans += result[a] - result[a - 1];
    }
    cout << ans << newl;

    return 0;
}
0