結果

問題 No.1140 EXPotentiaLLL!
ユーザー semisagi
提出日時 2020-07-31 21:31:39
言語 Swift
(6.0.3)
結果
AC  
実行時間 1,535 ms / 2,000 ms
コード長 1,140 bytes
コンパイル時間 10,127 ms
コンパイル使用メモリ 128,392 KB
実行使用メモリ 13,840 KB
最終ジャッジ日時 2024-07-06 16:35:48
合計ジャッジ時間 23,635 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

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)
    table[1] = false
    for i in 2 ... N where table[i] {
        for j in stride(from: i * 2, through: 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