結果

問題 No.1146 土偶Ⅰ
ユーザー phsplsphspls
提出日時 2020-08-05 23:15:34
言語 Rust
(1.77.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 171,100 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 23:31:37
合計ジャッジ時間 1,385 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::{min, max};

fn gcd(a: usize, b: usize) -> usize {
    if a % b == 0 { return b; }
    gcd(b, a % b)
}

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a: Vec<usize> = vec![];
    for _ in 0..n {
        let mut atemp = String::new();
        std::io::stdin().read_line(&mut atemp).ok();
        let atemp: usize = atemp.trim().parse().unwrap();
        a.push(atemp);
    }

    let mut result: usize = 0;
    for i in 0..n {
        for j in i+1..n {
            let temp = gcd(max(a[i], a[j]), min(a[i], a[j]));
            if temp == 1 {
                result += n - 1 - j;
                continue;
            }
            for k in j+1..n {
                if gcd(max(temp, a[k]), min(temp, a[k])) == 1 {
                    result += 1;
                }
            }
        }
    }
    println!("{}", result);
}
0