結果
問題 | No.1262 グラフを作ろう! |
ユーザー | koba-e964 |
提出日時 | 2020-10-22 19:59:47 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 250 ms / 3,000 ms |
コード長 | 2,339 bytes |
コンパイル時間 | 21,782 ms |
コンパイル使用メモリ | 391,372 KB |
実行使用メモリ | 33,280 KB |
最終ジャッジ日時 | 2024-07-21 09:29:39 |
合計ジャッジ時間 | 41,280 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 126 ms
19,200 KB |
testcase_01 | AC | 93 ms
15,208 KB |
testcase_02 | AC | 150 ms
23,680 KB |
testcase_03 | AC | 99 ms
14,208 KB |
testcase_04 | AC | 117 ms
21,052 KB |
testcase_05 | AC | 105 ms
18,176 KB |
testcase_06 | AC | 147 ms
24,448 KB |
testcase_07 | AC | 29 ms
6,656 KB |
testcase_08 | AC | 157 ms
25,428 KB |
testcase_09 | AC | 179 ms
10,076 KB |
testcase_10 | AC | 77 ms
12,928 KB |
testcase_11 | AC | 245 ms
27,800 KB |
testcase_12 | AC | 116 ms
17,664 KB |
testcase_13 | AC | 105 ms
14,976 KB |
testcase_14 | AC | 80 ms
13,952 KB |
testcase_15 | AC | 47 ms
8,064 KB |
testcase_16 | AC | 164 ms
24,420 KB |
testcase_17 | AC | 121 ms
20,532 KB |
testcase_18 | AC | 164 ms
26,240 KB |
testcase_19 | AC | 102 ms
18,944 KB |
testcase_20 | AC | 161 ms
27,008 KB |
testcase_21 | AC | 155 ms
24,192 KB |
testcase_22 | AC | 92 ms
17,360 KB |
testcase_23 | AC | 71 ms
11,264 KB |
testcase_24 | AC | 154 ms
25,268 KB |
testcase_25 | AC | 59 ms
11,928 KB |
testcase_26 | AC | 75 ms
14,208 KB |
testcase_27 | AC | 134 ms
22,768 KB |
testcase_28 | AC | 113 ms
19,712 KB |
testcase_29 | AC | 116 ms
20,864 KB |
testcase_30 | AC | 82 ms
14,588 KB |
testcase_31 | AC | 131 ms
20,352 KB |
testcase_32 | AC | 102 ms
17,124 KB |
testcase_33 | AC | 32 ms
6,528 KB |
testcase_34 | AC | 163 ms
27,264 KB |
testcase_35 | AC | 100 ms
15,360 KB |
testcase_36 | AC | 33 ms
6,272 KB |
testcase_37 | AC | 171 ms
26,824 KB |
testcase_38 | AC | 126 ms
21,248 KB |
testcase_39 | AC | 66 ms
10,368 KB |
testcase_40 | AC | 75 ms
12,672 KB |
testcase_41 | AC | 144 ms
22,912 KB |
testcase_42 | AC | 164 ms
26,496 KB |
testcase_43 | AC | 106 ms
18,304 KB |
testcase_44 | AC | 103 ms
17,400 KB |
testcase_45 | AC | 173 ms
27,904 KB |
testcase_46 | AC | 162 ms
25,956 KB |
testcase_47 | AC | 59 ms
9,756 KB |
testcase_48 | AC | 147 ms
24,320 KB |
testcase_49 | AC | 164 ms
25,856 KB |
testcase_50 | AC | 217 ms
26,496 KB |
testcase_51 | AC | 80 ms
12,288 KB |
testcase_52 | AC | 189 ms
24,832 KB |
testcase_53 | AC | 49 ms
9,344 KB |
testcase_54 | AC | 123 ms
18,176 KB |
testcase_55 | AC | 112 ms
17,152 KB |
testcase_56 | AC | 124 ms
21,960 KB |
testcase_57 | AC | 211 ms
30,464 KB |
testcase_58 | AC | 102 ms
15,976 KB |
testcase_59 | AC | 155 ms
23,040 KB |
testcase_60 | AC | 201 ms
28,416 KB |
testcase_61 | AC | 79 ms
13,056 KB |
testcase_62 | AC | 159 ms
23,528 KB |
testcase_63 | AC | 107 ms
17,024 KB |
testcase_64 | AC | 113 ms
16,256 KB |
testcase_65 | AC | 80 ms
13,952 KB |
testcase_66 | AC | 86 ms
14,080 KB |
testcase_67 | AC | 91 ms
16,384 KB |
testcase_68 | AC | 143 ms
25,728 KB |
testcase_69 | AC | 91 ms
15,488 KB |
testcase_70 | AC | 204 ms
28,416 KB |
testcase_71 | AC | 129 ms
22,144 KB |
testcase_72 | AC | 175 ms
28,732 KB |
testcase_73 | AC | 173 ms
25,636 KB |
testcase_74 | AC | 138 ms
20,992 KB |
testcase_75 | AC | 168 ms
23,424 KB |
testcase_76 | AC | 127 ms
21,504 KB |
testcase_77 | AC | 147 ms
22,044 KB |
testcase_78 | AC | 143 ms
24,004 KB |
testcase_79 | AC | 217 ms
29,976 KB |
testcase_80 | AC | 171 ms
28,800 KB |
testcase_81 | AC | 131 ms
21,548 KB |
testcase_82 | AC | 166 ms
24,040 KB |
testcase_83 | AC | 204 ms
27,264 KB |
testcase_84 | AC | 128 ms
21,888 KB |
testcase_85 | AC | 250 ms
30,336 KB |
testcase_86 | AC | 155 ms
23,552 KB |
testcase_87 | AC | 170 ms
27,672 KB |
testcase_88 | AC | 137 ms
21,376 KB |
testcase_89 | AC | 159 ms
25,984 KB |
testcase_90 | AC | 237 ms
33,020 KB |
testcase_91 | AC | 215 ms
33,280 KB |
testcase_92 | AC | 208 ms
33,152 KB |
testcase_93 | AC | 227 ms
33,152 KB |
testcase_94 | AC | 219 ms
33,128 KB |
testcase_95 | AC | 219 ms
33,024 KB |
ソースコード
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }}; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } fn main() { input! { n: usize, a: [usize], } let n = n + 1; // Problem: find \sum_{x: a} \sum_{j = 1}^x (gcd(x, j) - 1) let mut phi = vec![1i64; n]; let mut fac = vec![0; n]; for i in 1..n { fac[i] = i; } for i in 2..n { if fac[i] != i { continue; } for j in 2..(n - 1) / i + 1 { fac[i * j] = i; } } for i in 1..n { let mut v = i; let mut a = 1; while v > 1 { let p = fac[v]; let mut e = 0; while v % p == 0 { e += 1; v /= p; } a *= p - 1; for _ in 0..e - 1 { a *= p; } } phi[i] = a as i64; } // \sum_[j = 1}^x gcd(x, i) = \sum_{g | x} g * phi(x / g) let mut vals = vec![0; n]; for g in 1..n { for j in 1..(n - 1) / g + 1 { vals[g * j] += g as i64 * phi[j]; } } let mut tot = 0; // (RHS) = \sum {x: a} vals[x] - x for a in a { tot += vals[a] - a as i64; } println!("{}", tot); }