結果

問題 No.1200 お菓子配り-3
ユーザー 👑 箱
提出日時 2020-08-28 22:06:07
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 2,624 ms / 4,000 ms
コード長 1,706 bytes
コンパイル時間 17,073 ms
コンパイル使用メモリ 424,936 KB
実行使用メモリ 58,316 KB
最終ジャッジ日時 2023-08-13 05:48:45
合計ジャッジ時間 50,405 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
50,108 KB
testcase_01 AC 270 ms
52,032 KB
testcase_02 AC 316 ms
51,716 KB
testcase_03 AC 315 ms
51,632 KB
testcase_04 AC 297 ms
51,268 KB
testcase_05 AC 315 ms
51,532 KB
testcase_06 AC 296 ms
51,300 KB
testcase_07 AC 337 ms
53,376 KB
testcase_08 AC 335 ms
53,704 KB
testcase_09 AC 377 ms
53,640 KB
testcase_10 AC 314 ms
53,536 KB
testcase_11 AC 372 ms
53,560 KB
testcase_12 AC 538 ms
55,908 KB
testcase_13 AC 500 ms
55,852 KB
testcase_14 AC 530 ms
55,916 KB
testcase_15 AC 506 ms
55,796 KB
testcase_16 AC 518 ms
57,792 KB
testcase_17 AC 964 ms
57,920 KB
testcase_18 AC 1,241 ms
57,880 KB
testcase_19 AC 596 ms
56,316 KB
testcase_20 AC 1,932 ms
57,904 KB
testcase_21 AC 1,988 ms
58,268 KB
testcase_22 AC 2,237 ms
58,020 KB
testcase_23 AC 1,837 ms
58,316 KB
testcase_24 AC 1,906 ms
57,928 KB
testcase_25 AC 1,954 ms
57,856 KB
testcase_26 AC 2,011 ms
58,056 KB
testcase_27 AC 268 ms
50,632 KB
testcase_28 AC 2,436 ms
57,940 KB
testcase_29 AC 2,517 ms
58,192 KB
testcase_30 AC 2,624 ms
57,872 KB
testcase_31 AC 273 ms
50,512 KB
testcase_32 AC 270 ms
50,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val s = sc.nextInt()
    for (_i in 0 until s) {
        val x = sc.nextInt()
        val y = sc.nextInt()
        val cand_a = mutableSetOf<Long>()
        val n1 = x + y
        var d = 1
        while (d * d <= n1) {
            if (n1 % d == 0) {
                cand_a.add(d - 1L)
                cand_a.add(n1 / d - 1L)
            }
            d++
        }
        val n2 = Math.abs(x - y)
        d = 1
        while (d * d <= n2) {
            if (n2 % d == 0) {
                cand_a.add(d + 1L)
                cand_a.add(n2 / d + 1L)
            }
            d++
        }
        cand_a.remove(0)
        cand_a.remove(1)
        var ans = 0L
        for (a in cand_a) {
            val num = a * a - 1
            if (a * x > y && a * y > x && (a * x - y) % num == 0L && (a * y - x) % num == 0L) {
                ans++
            }
        }
        if (x == y) {
            ans += x - 1
        }
        println(ans)
    }
}

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

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    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()
    fun ready() = br.ready()
}
0