Skip to content

Commit f1631ca

Browse files
committed
Add an example for ABC162-C
1 parent 8630eee commit f1631ca

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

examples/abc162-c.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// https://atcoder.jp/contests/abc162/tasks/abc162_c
2+
//
3+
// 以下のクレートを使用。
4+
// - `num`
5+
// - `num-integer`
6+
// - `itertools`
7+
// - `proconio`
8+
9+
use itertools::iproduct;
10+
use proconio::input;
11+
12+
fn main() {
13+
// `proconio::input!`。
14+
//
15+
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
16+
input! {
17+
k: u64,
18+
}
19+
20+
// 三重ループを表わすイテレータを`itertools::iproduct!`で生み出す。
21+
// GCDは`num_integer::gcd`で`fold`することで求められる。
22+
//
23+
// https://docs.rs/itertools/0.9/itertools/macro.iproduct.html
24+
// https://docs.rs/num-integer/0.1/num_integer/fn.gcd.html
25+
let ans = iproduct!(1..=k, 1..=k, 1..=k)
26+
.map(|(a, b, c)| [a, b, c].iter().copied().fold(0, num::integer::gcd))
27+
.sum::<u64>();
28+
println!("{}", ans);
29+
}

test-examples.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ url = "https://atcoder.jp/contests/abc160/tasks/abc160_e"
226226
matching = "Words"
227227
meta = { using = ["itertools", "proconio"] }
228228

229+
[examples.abc162-c]
230+
type = "Normal"
231+
name = "ABC162 - C - Sum of gcd of Tuples (Easy)"
232+
url = "https://atcoder.jp/contests/abc162/tasks/abc162_c"
233+
matching = "Words"
234+
meta = { using = ["itertools", "num", "proconio"] }
235+
229236
[examples.agc020-c]
230237
type = "Normal"
231238
name = "AGC020: C - Median Sum"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy