結果

問題 No.1262 グラフを作ろう!
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-10-16 22:00:37
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 204 ms / 3,000 ms
コード長 2,055 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 108,072 KB
実行使用メモリ 60,220 KB
最終ジャッジ日時 2023-09-04 10:29:28
合計ジャッジ時間 30,416 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 185 ms
55,432 KB
testcase_01 AC 138 ms
36,648 KB
testcase_02 AC 183 ms
55,120 KB
testcase_03 AC 197 ms
56,628 KB
testcase_04 AC 60 ms
16,472 KB
testcase_05 AC 111 ms
25,808 KB
testcase_06 AC 56 ms
15,772 KB
testcase_07 AC 66 ms
17,576 KB
testcase_08 AC 129 ms
35,576 KB
testcase_09 AC 147 ms
37,640 KB
testcase_10 AC 118 ms
26,160 KB
testcase_11 AC 133 ms
35,572 KB
testcase_12 AC 170 ms
41,724 KB
testcase_13 AC 196 ms
56,748 KB
testcase_14 AC 106 ms
26,276 KB
testcase_15 AC 122 ms
35,676 KB
testcase_16 AC 135 ms
36,280 KB
testcase_17 AC 133 ms
36,136 KB
testcase_18 AC 183 ms
55,076 KB
testcase_19 AC 64 ms
17,412 KB
testcase_20 AC 92 ms
24,768 KB
testcase_21 AC 197 ms
57,168 KB
testcase_22 AC 57 ms
15,816 KB
testcase_23 AC 138 ms
36,252 KB
testcase_24 AC 137 ms
36,276 KB
testcase_25 AC 62 ms
16,848 KB
testcase_26 AC 76 ms
20,808 KB
testcase_27 AC 101 ms
25,712 KB
testcase_28 AC 97 ms
25,296 KB
testcase_29 AC 80 ms
21,404 KB
testcase_30 AC 92 ms
24,796 KB
testcase_31 AC 196 ms
57,160 KB
testcase_32 AC 127 ms
35,416 KB
testcase_33 AC 90 ms
25,312 KB
testcase_34 AC 111 ms
25,484 KB
testcase_35 AC 169 ms
41,520 KB
testcase_36 AC 96 ms
26,032 KB
testcase_37 AC 194 ms
56,580 KB
testcase_38 AC 119 ms
33,952 KB
testcase_39 AC 134 ms
36,080 KB
testcase_40 AC 119 ms
34,080 KB
testcase_41 AC 85 ms
22,124 KB
testcase_42 AC 158 ms
39,708 KB
testcase_43 AC 104 ms
24,480 KB
testcase_44 AC 119 ms
33,932 KB
testcase_45 AC 144 ms
37,844 KB
testcase_46 AC 76 ms
20,796 KB
testcase_47 AC 145 ms
39,764 KB
testcase_48 AC 142 ms
37,288 KB
testcase_49 AC 190 ms
56,244 KB
testcase_50 AC 149 ms
38,740 KB
testcase_51 AC 149 ms
39,268 KB
testcase_52 AC 81 ms
21,604 KB
testcase_53 AC 71 ms
18,872 KB
testcase_54 AC 189 ms
57,036 KB
testcase_55 AC 140 ms
37,512 KB
testcase_56 AC 85 ms
22,220 KB
testcase_57 AC 191 ms
57,072 KB
testcase_58 AC 177 ms
55,180 KB
testcase_59 AC 83 ms
21,788 KB
testcase_60 AC 188 ms
56,332 KB
testcase_61 AC 102 ms
24,560 KB
testcase_62 AC 179 ms
55,256 KB
testcase_63 AC 193 ms
57,528 KB
testcase_64 AC 133 ms
36,372 KB
testcase_65 AC 70 ms
18,244 KB
testcase_66 AC 104 ms
25,028 KB
testcase_67 AC 86 ms
22,304 KB
testcase_68 AC 69 ms
18,112 KB
testcase_69 AC 91 ms
24,804 KB
testcase_70 AC 135 ms
36,864 KB
testcase_71 AC 134 ms
36,520 KB
testcase_72 AC 151 ms
39,416 KB
testcase_73 AC 195 ms
57,672 KB
testcase_74 AC 182 ms
56,432 KB
testcase_75 AC 148 ms
38,784 KB
testcase_76 AC 130 ms
35,960 KB
testcase_77 AC 159 ms
40,892 KB
testcase_78 AC 140 ms
38,088 KB
testcase_79 AC 178 ms
55,196 KB
testcase_80 AC 129 ms
35,868 KB
testcase_81 AC 160 ms
40,952 KB
testcase_82 AC 191 ms
57,588 KB
testcase_83 AC 129 ms
35,784 KB
testcase_84 AC 131 ms
36,304 KB
testcase_85 AC 187 ms
56,908 KB
testcase_86 AC 156 ms
40,068 KB
testcase_87 AC 182 ms
55,772 KB
testcase_88 AC 158 ms
40,860 KB
testcase_89 AC 124 ms
35,204 KB
testcase_90 AC 189 ms
57,660 KB
testcase_91 AC 190 ms
59,536 KB
testcase_92 AC 190 ms
57,692 KB
testcase_93 AC 204 ms
60,220 KB
testcase_94 AC 191 ms
57,740 KB
testcase_95 AC 191 ms
58,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum LIM = 10^^6 + 10;

void main() {
  auto lpf = iota(LIM).array;
  foreach (p; 2 .. LIM) {
    if (lpf[p] == p) {
      for (int n = 2 * p; n < LIM; n += p) {
        chmin(lpf[n], p);
      }
    }
  }
  auto fs = new long[LIM];
  fs[1] = 1;
  foreach (n; 2 .. LIM) {
    const p = lpf[n];
    int e;
    int nn = n;
    do {
      ++e;
      nn /= p;
    } while (nn % p == 0);
    if (nn == 1) {
      fs[n] = 1L * n / p * (1L * (p - 1) * e + p);
    } else {
      fs[n] = fs[n / nn] * fs[nn];
    }
  }
  debug {
    writeln("fs = ", fs[0 .. 31]);
  }
  
  try {
    for (; ; ) {
      const N = readInt();
      const M = readInt();
      auto A = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt();
      }
      
      long ans;
      foreach (i; 0 .. M) {
        ans += fs[A[i]] - A[i];
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0