結果
| 問題 | 
                            No.3022 一元一次式 mod 1000000000
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-02-14 22:17:00 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,148 bytes | 
| コンパイル時間 | 214 ms | 
| コンパイル使用メモリ | 82,668 KB | 
| 実行使用メモリ | 90,768 KB | 
| 最終ジャッジ日時 | 2025-02-14 22:17:08 | 
| 合計ジャッジ時間 | 4,453 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 9 WA * 11 | 
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
def extended_euclid(a, b):
    if b == 0:
        return (1, 0)
    else:
        xd, yd = extended_euclid(b, a % b)
        return (yd, xd - a // b * yd)
input = sys.stdin.readline
#sys.setrecursionlimit(10**9)
t = int(input())
#alist = list(map(int,input().split()))
#alist = []
#s = input()
#n,m = map(int,input().split())
#for i in range(n):
#    alist.append(list(map(int,input().split())))
a = 2**9
b = 5**9
for i in range(t):
    n,m = map(int,input().split())
    if n % 1000000000 == 0:
        if m % 1000000000 == 0:
            print(1)
        else:
            print(-1)
        continue
    if m % 1000000000 == 0:
        ans = 1
        while n % a != 0:
            ans *= 2
            n *= 2
        while n % b != 0:
            ans *= 5
            n *= 5
        print(ans)
        continue
    n %= 1000000000
    m %= 1000000000
    if n % 2 == 0 or n % 5 == 0:
        print(-1)
        continue
    x = extended_euclid(n,1000000000)[0]
    ans = x*(-m) % 1000000000
    if ans == 0:
        ans = 1000000000
    print(ans)