結果

問題 No.1146 土偶Ⅰ
ユーザー
提出日時 2024-06-09 23:18:01
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 13,335 ms
コンパイル使用メモリ 400,820 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 03:59:29
合計ジャッジ時間 14,459 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn g(a: u64, b: u64) -> u64 {
	if b == 0 {
		a
	} else {
		g(b, a % b)
	}
}

fn main() {
	let mut s = String::new();
	std::io::stdin().read_to_string(&mut s).ok();
	let n: Vec<u64> = s.split_whitespace().flat_map(str::parse).collect();
	let mut a = 0;
	for i in 1..n.len() - 2 {
		for j in i + 1..n.len() - 1 {
			let d = g(n[i], n[j]);
			if d == 1 {
				a += n.len() - j - 1;
				continue;
			}
			for k in j + 1..n.len() {
				if g(d, n[k]) == 1 {
					a += 1;
				}
			}
		}
	}
	println!("{a}")
}
0