結果
| 問題 | 
                            No.3022 一元一次式 mod 1000000000
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-03-04 00:18:23 | 
| 言語 | C#  (.NET 8.0.404)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,655 bytes | 
| コンパイル時間 | 8,334 ms | 
| コンパイル使用メモリ | 170,544 KB | 
| 実行使用メモリ | 219,872 KB | 
| 最終ジャッジ日時 | 2025-03-04 00:18:35 | 
| 合計ジャッジ時間 | 11,469 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 8 WA * 13 | 
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (110 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = NN;
        var ans = new long[t];
        for (var u = 0; u < t; ++u)
        {
            var c = NList;
            var (n, m) = (c[0], c[1]);
            var d = 1_000_000_000;
            m %= d;
            var ex = XGcd(n, d);
            if ((d - m) % ex.g == 0)
            {
                var dx = d / ex.g;
                if (ex.x < 0) ans[u] = (ex.x + (-ex.x * d)) % dx * (d - m) % dx;
                else ans[u] = ex.x * (d - m) % dx;
            }
            else ans[u] = -1;
        }
        WriteLine(string.Join("\n", ans));
    }
    static long GCD(long a, long b)
    {
        if (a < b) return GCD(b, a);
        if (a % b == 0) return b;
        else return GCD(b, a % b);
    }
    // 拡張ユークリッド互除法 ax + by = gcd(a, b) を満たす x, y を求める
    static (long g, long x, long y) XGcd(long a, long b)
    {
        long x0 = 1, y0 = 0, x1 = 0, y1 = 1;
        while (b != 0)
        {
            var q = a / b;
            var prevA = a;
            a = b;
            b = prevA % b;
            var prevX0 = x0;
            var prevY0 = y0;
            x0 = x1;
            x1 = prevX0 - q * x1;
            y0 = y1;
            y1 = prevY0 - q * y1;
        }
        return (a, x0, y0);
    }
}