結果
| 問題 |
No.2767 Add to Divide
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-31 21:27:13 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 2,066 bytes |
| コンパイル時間 | 13,284 ms |
| コンパイル使用メモリ | 165,008 KB |
| 実行使用メモリ | 193,700 KB |
| 最終ジャッジ日時 | 2024-12-20 22:22:54 |
| 合計ジャッジ時間 | 15,452 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 16 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (98 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
namespace AtCoder;
#nullable enable
using System.Numerics;
static class Extensions
{
public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}
class AtCoder
{
object? Solve()
{
var t = Int();
var ans = t.Repeat(() => -1L);
for (var l = 0; l < t; l++)
{
var a = Int();
var b = Int();
var d = b - a;
var lns = long.MaxValue;
if (b % a == 0) lns = 0;
for (var i = 1L; i * i <= d; i++)
{
if (d % i != 0) continue;
var x = i - a;
if (x > 0) lns = Math.Min(lns, x);
var j = d / i;
x = j - a;
if (x > 0) lns = Math.Min(lns, x);
}
ans[l] = lns == long.MaxValue ? -1 : lns;
}
Out(ans);
return null;
}
public static void Main() => new AtCoder().Run();
public void Run()
{
var res = Solve();
if (res != null)
{
if (res is bool yes) res = yes ? "Yes" : "No";
sw.WriteLine(res);
}
sw.Flush();
}
string[] input = Array.Empty<string>();
int iter = 0;
readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };
string String()
{
while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
return input[iter++];
}
T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
int Int() => Input<int>();
void Out(object? x, string? separator = null)
{
separator ??= Environment.NewLine;
if (x is System.Collections.IEnumerable obj and not string)
{
var firstLine = true;
foreach (var item in obj)
{
if (!firstLine) sw.Write(separator);
firstLine = false;
sw.Write(item);
}
}
else sw.Write(x);
sw.WriteLine();
}
}