結果
問題 | No.1262 グラフを作ろう! |
ユーザー | koba-e964 |
提出日時 | 2020-10-22 19:52:30 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 379 ms / 3,000 ms |
コード長 | 3,346 bytes |
コンパイル時間 | 16,898 ms |
コンパイル使用メモリ | 378,372 KB |
実行使用メモリ | 33,280 KB |
最終ジャッジ日時 | 2024-07-21 09:27:15 |
合計ジャッジ時間 | 41,259 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 111 ms
19,456 KB |
testcase_01 | AC | 268 ms
15,232 KB |
testcase_02 | AC | 379 ms
23,808 KB |
testcase_03 | AC | 296 ms
14,208 KB |
testcase_04 | AC | 111 ms
21,120 KB |
testcase_05 | AC | 242 ms
18,304 KB |
testcase_06 | AC | 136 ms
24,320 KB |
testcase_07 | AC | 49 ms
6,400 KB |
testcase_08 | AC | 201 ms
25,600 KB |
testcase_09 | AC | 127 ms
10,112 KB |
testcase_10 | AC | 108 ms
13,056 KB |
testcase_11 | AC | 222 ms
27,776 KB |
testcase_12 | AC | 184 ms
17,536 KB |
testcase_13 | AC | 174 ms
15,104 KB |
testcase_14 | AC | 135 ms
13,952 KB |
testcase_15 | AC | 139 ms
8,192 KB |
testcase_16 | AC | 142 ms
24,448 KB |
testcase_17 | AC | 210 ms
20,480 KB |
testcase_18 | AC | 247 ms
26,368 KB |
testcase_19 | AC | 122 ms
19,072 KB |
testcase_20 | AC | 194 ms
27,136 KB |
testcase_21 | AC | 191 ms
24,192 KB |
testcase_22 | AC | 96 ms
17,280 KB |
testcase_23 | AC | 130 ms
11,264 KB |
testcase_24 | AC | 145 ms
25,344 KB |
testcase_25 | AC | 56 ms
11,904 KB |
testcase_26 | AC | 70 ms
14,208 KB |
testcase_27 | AC | 162 ms
22,784 KB |
testcase_28 | AC | 128 ms
19,712 KB |
testcase_29 | AC | 123 ms
20,864 KB |
testcase_30 | AC | 112 ms
14,720 KB |
testcase_31 | AC | 156 ms
20,352 KB |
testcase_32 | AC | 121 ms
17,152 KB |
testcase_33 | AC | 41 ms
6,400 KB |
testcase_34 | AC | 279 ms
27,392 KB |
testcase_35 | AC | 128 ms
15,360 KB |
testcase_36 | AC | 77 ms
6,272 KB |
testcase_37 | AC | 269 ms
26,880 KB |
testcase_38 | AC | 120 ms
21,248 KB |
testcase_39 | AC | 70 ms
10,368 KB |
testcase_40 | AC | 122 ms
12,672 KB |
testcase_41 | AC | 160 ms
22,912 KB |
testcase_42 | AC | 215 ms
26,624 KB |
testcase_43 | AC | 110 ms
18,432 KB |
testcase_44 | AC | 92 ms
17,408 KB |
testcase_45 | AC | 168 ms
27,904 KB |
testcase_46 | AC | 150 ms
25,984 KB |
testcase_47 | AC | 77 ms
9,856 KB |
testcase_48 | AC | 139 ms
24,192 KB |
testcase_49 | AC | 178 ms
25,856 KB |
testcase_50 | AC | 180 ms
26,496 KB |
testcase_51 | AC | 69 ms
12,160 KB |
testcase_52 | AC | 138 ms
24,832 KB |
testcase_53 | AC | 41 ms
9,216 KB |
testcase_54 | AC | 104 ms
18,176 KB |
testcase_55 | AC | 92 ms
17,152 KB |
testcase_56 | AC | 114 ms
22,016 KB |
testcase_57 | AC | 183 ms
30,464 KB |
testcase_58 | AC | 103 ms
16,128 KB |
testcase_59 | AC | 124 ms
23,040 KB |
testcase_60 | AC | 193 ms
28,544 KB |
testcase_61 | AC | 98 ms
13,056 KB |
testcase_62 | AC | 150 ms
23,424 KB |
testcase_63 | AC | 101 ms
17,024 KB |
testcase_64 | AC | 99 ms
16,384 KB |
testcase_65 | AC | 67 ms
13,952 KB |
testcase_66 | AC | 73 ms
14,208 KB |
testcase_67 | AC | 81 ms
16,384 KB |
testcase_68 | AC | 142 ms
25,728 KB |
testcase_69 | AC | 77 ms
15,616 KB |
testcase_70 | AC | 188 ms
28,416 KB |
testcase_71 | AC | 121 ms
22,272 KB |
testcase_72 | AC | 170 ms
28,800 KB |
testcase_73 | AC | 149 ms
25,856 KB |
testcase_74 | AC | 116 ms
20,992 KB |
testcase_75 | AC | 129 ms
23,552 KB |
testcase_76 | AC | 116 ms
21,504 KB |
testcase_77 | AC | 125 ms
22,144 KB |
testcase_78 | AC | 319 ms
24,064 KB |
testcase_79 | AC | 237 ms
30,208 KB |
testcase_80 | AC | 198 ms
28,800 KB |
testcase_81 | AC | 290 ms
21,632 KB |
testcase_82 | AC | 303 ms
24,064 KB |
testcase_83 | AC | 205 ms
27,392 KB |
testcase_84 | AC | 155 ms
22,016 KB |
testcase_85 | AC | 205 ms
30,464 KB |
testcase_86 | AC | 140 ms
23,680 KB |
testcase_87 | AC | 163 ms
27,776 KB |
testcase_88 | AC | 120 ms
21,504 KB |
testcase_89 | AC | 155 ms
26,112 KB |
testcase_90 | AC | 239 ms
33,152 KB |
testcase_91 | AC | 204 ms
33,280 KB |
testcase_92 | AC | 229 ms
33,024 KB |
testcase_93 | AC | 236 ms
33,152 KB |
testcase_94 | AC | 211 ms
33,024 KB |
testcase_95 | AC | 199 ms
33,152 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::{Write, BufWriter}; // 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, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($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") }; } #[allow(unused)] macro_rules! debug { ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap()); } #[allow(unused)] macro_rules! debugln { ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap()); } fn solve() { let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); macro_rules! puts { ($($format:tt)*) => (let _ = write!(out,$($format)*);); } 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; } puts!("{}\n", tot); } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); }