結果
| 問題 |
No.136 Yet Another GCD Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-06 17:07:31 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 728 bytes |
| コンパイル時間 | 1,838 ms |
| コンパイル使用メモリ | 196,852 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-10-06 17:07:40 |
| 合計ジャッジ時間 | 3,480 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
module main;
// https://yukicoder.me/problems/no/136/editorial より
// 素因数分解
import std;
// https://qiita.com/LorseKudos/items/9eb560494862c8b4eb56 より
// 整数nの約数を列挙する
long[] divisors(long n)
{
long[] lowerDivisors = [1], upperDivisors = [n];
if (n % 2 == 0) {
lowerDivisors ~= 2;
upperDivisors ~= n / 2;
}
long i = 3;
for (; i * i < n; i += 2) {
if (n % i != 0) continue;
lowerDivisors ~= i;
upperDivisors ~= n / i;
}
if (i * i == n)
lowerDivisors ~= i;
return lowerDivisors ~ upperDivisors.reverse;
}
void main()
{
// 入力
int N, K;
readln.chomp.formattedRead("%d %d", N, K);
// 答えの計算
auto div = divisors(N);
// 答えの出力
writeln(div[$ - 2]);
}