結果

問題 No.1146 土偶Ⅰ
ユーザー bluemeganebluemegane
提出日時 2021-04-16 20:28:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,525 bytes
コンパイル時間 2,725 ms
コンパイル使用メモリ 67,652 KB
実行使用メモリ 29,792 KB
最終ジャッジ日時 2023-09-15 21:16:13
合計ジャッジ時間 4,811 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
23,716 KB
testcase_01 AC 61 ms
21,624 KB
testcase_02 AC 61 ms
21,636 KB
testcase_03 AC 78 ms
25,732 KB
testcase_04 AC 197 ms
27,740 KB
testcase_05 AC 83 ms
23,784 KB
testcase_06 AC 127 ms
25,704 KB
testcase_07 AC 171 ms
25,784 KB
testcase_08 AC 198 ms
27,900 KB
testcase_09 AC 106 ms
25,856 KB
testcase_10 AC 75 ms
27,776 KB
testcase_11 AC 121 ms
27,716 KB
testcase_12 AC 202 ms
29,792 KB
testcase_13 AC 61 ms
21,592 KB
testcase_14 AC 103 ms
27,788 KB
testcase_15 AC 175 ms
29,692 KB
testcase_16 AC 114 ms
25,644 KB
testcase_17 AC 61 ms
21,652 KB
testcase_18 AC 63 ms
21,648 KB
testcase_19 AC 107 ms
27,672 KB
testcase_20 AC 63 ms
23,592 KB
testcase_21 AC 74 ms
25,656 KB
testcase_22 AC 67 ms
23,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
using System;

public static class combi
{
    public static IEnumerable<IEnumerable<T>> Comb<T>(this IEnumerable<T> items, int r)
    {
        if (r == 0)
        {
            yield return Enumerable.Empty<T>();
        }
        else
        {
            var i = 1;
            foreach (var x in items)
            {
                var xs = items.Skip(i);
                foreach (var c in Comb(xs, r - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items)
            yield return i;
    }
}

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a = new int[n];
        for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim());
        getAns(n, a);
    }
    static void getAns(int n, int[] a)
    {
        var count = 0;
        var b = Enumerable.Range(0, n).Comb(3);
        foreach (var x in b)
        {
            var c = x.ToArray();
            var k = Gcd(a[c[0]], Gcd(a[c[1]], a[c[2]]));
            if (k == 1) count++;
        }
        Console.WriteLine(count);
    }
    static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}
0