結果

問題 No.1140 EXPotentiaLLL!
ユーザー semisagisemisagi
提出日時 2020-07-31 21:31:39
言語 Swift
(5.10.0)
結果
AC  
実行時間 1,523 ms / 2,000 ms
コード長 1,140 bytes
コンパイル時間 5,500 ms
コンパイル使用メモリ 132,156 KB
実行使用メモリ 12,240 KB
最終ジャッジ日時 2023-09-20 21:48:22
合計ジャッジ時間 19,712 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,505 ms
11,224 KB
testcase_01 AC 1,501 ms
11,312 KB
testcase_02 AC 1,523 ms
11,180 KB
testcase_03 AC 1,071 ms
11,412 KB
testcase_04 AC 819 ms
11,276 KB
testcase_05 AC 1,306 ms
11,292 KB
testcase_06 AC 1,252 ms
11,248 KB
testcase_07 AC 1,464 ms
12,232 KB
testcase_08 AC 36 ms
11,168 KB
testcase_09 AC 36 ms
11,304 KB
testcase_10 AC 37 ms
11,184 KB
testcase_11 AC 38 ms
11,244 KB
testcase_12 AC 37 ms
12,240 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, 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