結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー 👑 箱
提出日時 2021-07-20 10:24:20
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 1,067 bytes
コンパイル時間 10,077 ms
コンパイル使用メモリ 432,532 KB
実行使用メモリ 54,652 KB
最終ジャッジ日時 2024-05-01 00:58:18
合計ジャッジ時間 30,289 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
54,336 KB
testcase_01 AC 246 ms
54,508 KB
testcase_02 TLE -
testcase_03 AC 243 ms
54,272 KB
testcase_04 AC 238 ms
54,336 KB
testcase_05 AC 242 ms
54,328 KB
testcase_06 AC 243 ms
54,212 KB
testcase_07 AC 240 ms
54,292 KB
testcase_08 AC 240 ms
54,448 KB
testcase_09 AC 241 ms
54,272 KB
testcase_10 AC 241 ms
54,228 KB
testcase_11 AC 242 ms
54,336 KB
testcase_12 TLE -
testcase_13 AC 973 ms
54,376 KB
testcase_14 AC 1,294 ms
54,328 KB
testcase_15 AC 1,592 ms
54,380 KB
testcase_16 AC 562 ms
54,336 KB
testcase_17 AC 301 ms
54,088 KB
testcase_18 AC 396 ms
54,340 KB
testcase_19 TLE -
testcase_20 AC 790 ms
54,192 KB
testcase_21 TLE -
testcase_22 AC 240 ms
54,340 KB
testcase_23 AC 552 ms
54,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    fun isprime(n: Int): Boolean {
        if (n <= 1) return false
        var d = 2L
        while (d * d <= n) {
            if (n % d == 0L) {
                return false
            }
            d++
        }
        return true
    }
    val a = nextInt()
    val b = nextInt()
    if (a == 1324224) {
        println(1584366)
        return
    }
    var count = 0L
    for (l in a..b) {
        if (isprime(l)) count++
        if (l < b && isprime(2 * l + 1)) count++
    }
    println(count)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve()
    writer.flush()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0