結果
問題 |
No.1146 土偶Ⅰ
|
ユーザー |
![]() |
提出日時 | 2021-04-16 20:34:10 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 173 ms / 2,000 ms |
コード長 | 1,601 bytes |
コンパイル時間 | 2,166 ms |
コンパイル使用メモリ | 115,004 KB |
実行使用メモリ | 33,080 KB |
最終ジャッジ日時 | 2024-07-02 22:56:45 |
合計ジャッジ時間 | 4,521 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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 k0 = Gcd(a[c[1]], a[c[2]]); if (k0 == 1) { count++; continue; } var k1 = Gcd(a[c[0]], k0); if (k1 == 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; } }