結果

問題 No.1262 グラフを作ろう!
ユーザー 👑 emthrmemthrm
提出日時 2020-10-16 23:31:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 3,000 ms
コード長 1,760 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 201,556 KB
実行使用メモリ 15,016 KB
最終ジャッジ日時 2023-09-28 05:39:29
合計ジャッジ時間 19,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
8,320 KB
testcase_01 AC 77 ms
7,248 KB
testcase_02 AC 118 ms
10,632 KB
testcase_03 AC 95 ms
5,372 KB
testcase_04 AC 58 ms
12,308 KB
testcase_05 AC 72 ms
9,548 KB
testcase_06 AC 67 ms
14,092 KB
testcase_07 AC 18 ms
4,852 KB
testcase_08 AC 102 ms
12,944 KB
testcase_09 AC 60 ms
4,620 KB
testcase_10 AC 57 ms
7,008 KB
testcase_11 AC 112 ms
14,004 KB
testcase_12 AC 94 ms
7,572 KB
testcase_13 AC 96 ms
5,988 KB
testcase_14 AC 56 ms
7,568 KB
testcase_15 AC 47 ms
4,376 KB
testcase_16 AC 99 ms
12,144 KB
testcase_17 AC 86 ms
9,976 KB
testcase_18 AC 121 ms
11,936 KB
testcase_19 AC 48 ms
11,404 KB
testcase_20 AC 93 ms
14,636 KB
testcase_21 AC 124 ms
10,420 KB
testcase_22 AC 44 ms
10,576 KB
testcase_23 AC 65 ms
5,580 KB
testcase_24 AC 110 ms
12,408 KB
testcase_25 AC 32 ms
7,776 KB
testcase_26 AC 42 ms
8,468 KB
testcase_27 AC 80 ms
12,224 KB
testcase_28 AC 69 ms
10,880 KB
testcase_29 AC 66 ms
11,824 KB
testcase_30 AC 53 ms
8,264 KB
testcase_31 AC 115 ms
8,480 KB
testcase_32 AC 76 ms
8,468 KB
testcase_33 AC 28 ms
4,380 KB
testcase_34 AC 105 ms
14,072 KB
testcase_35 AC 91 ms
6,480 KB
testcase_36 AC 30 ms
4,376 KB
testcase_37 AC 134 ms
11,840 KB
testcase_38 AC 82 ms
10,792 KB
testcase_39 AC 63 ms
5,216 KB
testcase_40 AC 59 ms
6,780 KB
testcase_41 AC 76 ms
12,656 KB
testcase_42 AC 119 ms
12,600 KB
testcase_43 AC 71 ms
9,880 KB
testcase_44 AC 71 ms
9,000 KB
testcase_45 AC 121 ms
13,928 KB
testcase_46 AC 81 ms
14,596 KB
testcase_47 AC 62 ms
4,380 KB
testcase_48 AC 102 ms
11,940 KB
testcase_49 AC 123 ms
11,396 KB
testcase_50 AC 112 ms
12,580 KB
testcase_51 AC 70 ms
5,392 KB
testcase_52 AC 79 ms
13,656 KB
testcase_53 AC 30 ms
6,168 KB
testcase_54 AC 104 ms
7,536 KB
testcase_55 AC 82 ms
8,304 KB
testcase_56 AC 67 ms
12,348 KB
testcase_57 AC 150 ms
13,764 KB
testcase_58 AC 92 ms
6,796 KB
testcase_59 AC 74 ms
12,828 KB
testcase_60 AC 139 ms
13,024 KB
testcase_61 AC 52 ms
7,232 KB
testcase_62 AC 114 ms
10,248 KB
testcase_63 AC 100 ms
6,780 KB
testcase_64 AC 74 ms
8,068 KB
testcase_65 AC 39 ms
8,564 KB
testcase_66 AC 56 ms
7,668 KB
testcase_67 AC 53 ms
9,388 KB
testcase_68 AC 75 ms
14,352 KB
testcase_69 AC 53 ms
8,764 KB
testcase_70 AC 115 ms
13,920 KB
testcase_71 AC 89 ms
10,792 KB
testcase_72 AC 125 ms
13,720 KB
testcase_73 AC 122 ms
11,072 KB
testcase_74 AC 102 ms
9,040 KB
testcase_75 AC 100 ms
11,052 KB
testcase_76 AC 84 ms
10,528 KB
testcase_77 AC 99 ms
9,996 KB
testcase_78 AC 100 ms
11,660 KB
testcase_79 AC 139 ms
13,652 KB
testcase_80 AC 119 ms
14,156 KB
testcase_81 AC 99 ms
9,804 KB
testcase_82 AC 114 ms
10,240 KB
testcase_83 AC 106 ms
13,716 KB
testcase_84 AC 85 ms
10,984 KB
testcase_85 AC 139 ms
13,628 KB
testcase_86 AC 102 ms
10,884 KB
testcase_87 AC 128 ms
12,492 KB
testcase_88 AC 98 ms
9,648 KB
testcase_89 AC 102 ms
13,128 KB
testcase_90 AC 143 ms
14,608 KB
testcase_91 AC 144 ms
14,888 KB
testcase_92 AC 146 ms
14,652 KB
testcase_93 AC 151 ms
15,016 KB
testcase_94 AC 145 ms
14,688 KB
testcase_95 AC 143 ms
14,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

std::vector<int> euler_phi_init(int val) {
  std::vector<int> phi(val + 1);
  for (int i = 0; i <= val; ++i) phi[i] = i;
  for (int i = 2; i <= val; ++i) {
    if (phi[i] == i) {
      for (int j = i; j <= val; j += i) phi[j] -= phi[j] / i;
    }
  }
  return phi;
}

int main() {
  int n, m; cin >> n >> m;
  // https://oeis.org/A006579
  vector<int> phi = euler_phi_init(n);
  vector<ll> s(n + 1, 0);
  FOR(i, 2, n + 1) for (int j = i; j <= n; j += i) s[j] += 1LL * (i - 1) * phi[j / i];
  // REP(a, n + 1) {
  //   ll sum = 0;
  //   FOR(b, 1, a + 1) {
  //     int mn = a - 1, y = (a - 1 - b + a) % a;
  //     while (y != a - 1) {
  //       chmin(mn, y);
  //       y = (y - b + a) % a;
  //     }
  //     sum += mn;
  //   }
  //   cout << sum << " \n"[a == n];
  // }
  ll ans = 0;
  while (m--) {
    int a; cin >> a;
    ans += s[a];
  }
  cout << ans << '\n';
  return 0;
}
0