結果
| 問題 | 
                            No.3022 一元一次式 mod 1000000000
                             | 
                    
| コンテスト | |
| ユーザー | 
                             titia
                         | 
                    
| 提出日時 | 2025-02-16 01:30:26 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                            (最新)
                                AC
                                 
                             
                            (最初)
                            
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 603 bytes | 
| コンパイル時間 | 273 ms | 
| コンパイル使用メモリ | 11,904 KB | 
| 実行使用メモリ | 10,112 KB | 
| 最終ジャッジ日時 | 2025-02-17 12:58:46 | 
| 合計ジャッジ時間 | 2,529 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 WA * 1 | 
ソースコード
import sys
input = sys.stdin.readline
def p(x,m):
    ANS=0
    while x%m==0:
        ANS+=1
        x//=m
    return ANS
T=int(input())
for tests in range(T):
    N,M=map(int,input().split())
    N2=p(N,2)
    N5=p(N,5)
    M2=p(M,2)
    M5=p(M,5)
    if min(N2,9)<=M2 and min(N5,9)<=M5:
        pass
    else:
        print(-1)
        continue
    d=(2**min(N2,9))*(5**min(N5,9))
    
    N//=d
    M//=d
    mod=10**9
    mod//=d
    if mod==1:
        print(1)
        continue
    k=-M*pow(N,-1,mod)%mod
    if k==0:
        print(min(mod,M)//N)
    else:
        print(k)
    
    
            
            
            
        
            
titia