結果
| 問題 | No.917 Make One With GCD |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-14 23:23:56 |
| 言語 | C# (.NET 10.0.101) |
| 結果 |
AC
|
| 実行時間 | 77 ms / 2,000 ms |
| コード長 | 1,360 bytes |
| 記録 | |
| コンパイル時間 | 10,986 ms |
| コンパイル使用メモリ | 167,964 KB |
| 実行使用メモリ | 193,340 KB |
| 最終ジャッジ日時 | 2026-01-14 23:24:12 |
| 合計ジャッジ時間 | 13,288 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (169 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net10.0/main.dll main -> /home/judge/data/code/bin/Release/net10.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
using System.Security.Cryptography;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var n = NN;
var a = NList;
Array.Sort(a);
var dic = new Dictionary<int, long>();
dic[a[0]] = 1;
for (var i = 1; i < n; ++i)
{
var ndic = new Dictionary<int, long>();
ndic[a[i]] = 1;
foreach (var kv in dic)
{
if (ndic.ContainsKey(kv.Key)) ndic[kv.Key] += kv.Value;
else ndic[kv.Key] = kv.Value;
var gcd = GCD(kv.Key, a[i]);
if (ndic.ContainsKey(gcd)) ndic[gcd] += kv.Value;
else ndic[gcd] = kv.Value;
}
dic = ndic;
}
if (dic.ContainsKey(1)) WriteLine(dic[1]);
else WriteLine(0);
}
static int GCD(int a, int b)
{
if (a < b) return GCD(b, a);
if (a % b == 0) return b;
return GCD(b, a % b);
}
}