結果

問題 No.1140 EXPotentiaLLL!
ユーザー semisagisemisagi
提出日時 2020-07-31 21:27:51
言語 Swift
(5.10.0)
結果
WA  
実行時間 -
コード長 1,135 bytes
コンパイル時間 4,854 ms
コンパイル使用メモリ 132,064 KB
実行使用メモリ 12,284 KB
最終ジャッジ日時 2023-09-20 21:35:07
合計ジャッジ時間 19,251 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,508 ms
11,420 KB
testcase_01 WA -
testcase_02 AC 1,517 ms
11,436 KB
testcase_03 AC 1,051 ms
11,244 KB
testcase_04 AC 827 ms
11,280 KB
testcase_05 AC 1,307 ms
11,384 KB
testcase_06 AC 1,213 ms
11,340 KB
testcase_07 AC 1,487 ms
11,380 KB
testcase_08 AC 39 ms
11,284 KB
testcase_09 AC 39 ms
11,196 KB
testcase_10 AC 39 ms
11,296 KB
testcase_11 AC 38 ms
12,284 KB
testcase_12 AC 38 ms
11,384 KB
権限があれば一括ダウンロードができます

ソースコード

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, 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