結果

問題 No.1262 グラフを作ろう!
ユーザー msm1993msm1993
提出日時 2020-10-23 15:40:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 3,000 ms
コード長 1,462 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 163,388 KB
実行使用メモリ 19,236 KB
最終ジャッジ日時 2023-09-28 15:26:57
合計ジャッジ時間 28,759 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
19,056 KB
testcase_01 AC 165 ms
19,044 KB
testcase_02 AC 202 ms
19,108 KB
testcase_03 AC 194 ms
18,980 KB
testcase_04 AC 110 ms
19,048 KB
testcase_05 AC 149 ms
19,008 KB
testcase_06 AC 108 ms
18,968 KB
testcase_07 AC 112 ms
18,968 KB
testcase_08 AC 169 ms
18,976 KB
testcase_09 AC 192 ms
18,972 KB
testcase_10 AC 146 ms
19,196 KB
testcase_11 AC 179 ms
19,196 KB
testcase_12 AC 202 ms
19,124 KB
testcase_13 AC 198 ms
18,984 KB
testcase_14 AC 145 ms
19,056 KB
testcase_15 AC 147 ms
19,032 KB
testcase_16 AC 181 ms
18,956 KB
testcase_17 AC 170 ms
19,044 KB
testcase_18 AC 223 ms
18,968 KB
testcase_19 AC 114 ms
18,952 KB
testcase_20 AC 136 ms
19,120 KB
testcase_21 AC 229 ms
18,956 KB
testcase_22 AC 108 ms
19,196 KB
testcase_23 AC 159 ms
18,972 KB
testcase_24 AC 175 ms
19,192 KB
testcase_25 AC 111 ms
18,972 KB
testcase_26 AC 120 ms
19,032 KB
testcase_27 AC 144 ms
18,952 KB
testcase_28 AC 142 ms
18,976 KB
testcase_29 AC 124 ms
18,952 KB
testcase_30 AC 133 ms
19,048 KB
testcase_31 AC 201 ms
19,032 KB
testcase_32 AC 161 ms
19,008 KB
testcase_33 AC 129 ms
18,980 KB
testcase_34 AC 159 ms
19,048 KB
testcase_35 AC 186 ms
19,008 KB
testcase_36 AC 131 ms
18,956 KB
testcase_37 AC 229 ms
19,048 KB
testcase_38 AC 168 ms
19,196 KB
testcase_39 AC 162 ms
18,968 KB
testcase_40 AC 154 ms
18,956 KB
testcase_41 AC 134 ms
18,968 KB
testcase_42 AC 208 ms
19,180 KB
testcase_43 AC 144 ms
19,012 KB
testcase_44 AC 159 ms
18,984 KB
testcase_45 AC 185 ms
19,160 KB
testcase_46 AC 123 ms
19,124 KB
testcase_47 AC 166 ms
18,972 KB
testcase_48 AC 178 ms
19,124 KB
testcase_49 AC 206 ms
18,968 KB
testcase_50 AC 191 ms
18,980 KB
testcase_51 AC 166 ms
19,036 KB
testcase_52 AC 124 ms
19,032 KB
testcase_53 AC 117 ms
19,108 KB
testcase_54 AC 198 ms
18,972 KB
testcase_55 AC 165 ms
18,988 KB
testcase_56 AC 126 ms
18,952 KB
testcase_57 AC 217 ms
19,120 KB
testcase_58 AC 184 ms
18,984 KB
testcase_59 AC 123 ms
19,056 KB
testcase_60 AC 203 ms
19,184 KB
testcase_61 AC 138 ms
18,956 KB
testcase_62 AC 199 ms
19,052 KB
testcase_63 AC 197 ms
19,112 KB
testcase_64 AC 159 ms
18,980 KB
testcase_65 AC 116 ms
19,120 KB
testcase_66 AC 146 ms
19,112 KB
testcase_67 AC 125 ms
18,980 KB
testcase_68 AC 124 ms
19,056 KB
testcase_69 AC 127 ms
18,980 KB
testcase_70 AC 166 ms
19,176 KB
testcase_71 AC 159 ms
19,052 KB
testcase_72 AC 193 ms
18,980 KB
testcase_73 AC 203 ms
19,236 KB
testcase_74 AC 184 ms
18,972 KB
testcase_75 AC 178 ms
19,236 KB
testcase_76 AC 159 ms
19,048 KB
testcase_77 AC 187 ms
18,972 KB
testcase_78 AC 178 ms
19,060 KB
testcase_79 AC 200 ms
19,048 KB
testcase_80 AC 168 ms
19,196 KB
testcase_81 AC 176 ms
18,968 KB
testcase_82 AC 198 ms
19,120 KB
testcase_83 AC 159 ms
18,972 KB
testcase_84 AC 156 ms
19,124 KB
testcase_85 AC 208 ms
19,168 KB
testcase_86 AC 183 ms
18,984 KB
testcase_87 AC 192 ms
18,976 KB
testcase_88 AC 180 ms
18,956 KB
testcase_89 AC 161 ms
19,028 KB
testcase_90 AC 189 ms
18,972 KB
testcase_91 AC 210 ms
18,980 KB
testcase_92 AC 189 ms
18,984 KB
testcase_93 AC 195 ms
19,116 KB
testcase_94 AC 188 ms
19,044 KB
testcase_95 AC 193 ms
19,028 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