結果
| 問題 |
No.1146 土偶Ⅰ
|
| ユーザー |
bluemegane
|
| 提出日時 | 2021-04-16 20:28:08 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 191 ms / 2,000 ms |
| コード長 | 1,525 bytes |
| コンパイル時間 | 2,219 ms |
| コンパイル使用メモリ | 115,880 KB |
| 実行使用メモリ | 33,204 KB |
| 最終ジャッジ日時 | 2024-07-02 22:44:56 |
| 合計ジャッジ時間 | 5,153 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 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;
}
}
bluemegane