結果

問題 No.1140 EXPotentiaLLL!
ユーザー semisagi
提出日時 2020-07-31 21:26:26
言語 Swift
(6.0.3)
結果
WA  
実行時間 -
コード長 1,114 bytes
コンパイル時間 14,063 ms
コンパイル使用メモリ 128,604 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-07-06 16:18:16
合計ジャッジ時間 27,053 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

fileprivate struct Scanner {
    private var elements = [String]()
    private var index = 0
    
    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }
    
    mutating func next() -> String {
        let value = peek()
        index += 1
        return value
    }
    
    mutating func nextInt() -> Int {
        return Int(next())!
    }
    
    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

func main() {
    var scanner = Scanner()
    
    let N = 5000000
    var table = [Bool](repeating: true, count: N + 1)
    for i in 2 ... N where table[i] {
        for j in stride(from: i * 2, to: N, by: i) {
            table[j] = false
        }
    }
    
    let T = scanner.nextInt()
    for _ in 0 ..< T {
        let A = scanner.nextInt()
        let P = scanner.nextInt()
        
        if table[P] {
            print(A % P == 0 ? 0 : 1)
        } else {
            print(-1)
        }
    }
}

main()
0