結果

問題 No.1200 お菓子配り-3
ユーザー 👑 箱星箱星
提出日時 2020-08-28 22:06:07
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 2,386 ms / 4,000 ms
コード長 1,706 bytes
コンパイル時間 13,692 ms
コンパイル使用メモリ 438,276 KB
実行使用メモリ 88,748 KB
最終ジャッジ日時 2024-04-30 23:47:48
合計ジャッジ時間 41,814 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 249 ms
54,372 KB
testcase_01 AC 242 ms
54,384 KB
testcase_02 AC 281 ms
55,764 KB
testcase_03 AC 284 ms
55,788 KB
testcase_04 AC 268 ms
55,400 KB
testcase_05 AC 288 ms
55,592 KB
testcase_06 AC 266 ms
55,344 KB
testcase_07 AC 305 ms
55,796 KB
testcase_08 AC 302 ms
55,732 KB
testcase_09 AC 340 ms
55,992 KB
testcase_10 AC 294 ms
55,456 KB
testcase_11 AC 365 ms
55,984 KB
testcase_12 AC 481 ms
60,048 KB
testcase_13 AC 456 ms
60,140 KB
testcase_14 AC 468 ms
60,124 KB
testcase_15 AC 456 ms
60,232 KB
testcase_16 AC 466 ms
58,064 KB
testcase_17 AC 884 ms
67,948 KB
testcase_18 AC 1,113 ms
72,024 KB
testcase_19 AC 536 ms
60,072 KB
testcase_20 AC 1,692 ms
86,680 KB
testcase_21 AC 1,913 ms
88,748 KB
testcase_22 AC 1,954 ms
88,620 KB
testcase_23 AC 1,672 ms
86,748 KB
testcase_24 AC 1,752 ms
84,496 KB
testcase_25 AC 1,757 ms
84,420 KB
testcase_26 AC 1,777 ms
84,664 KB
testcase_27 AC 248 ms
54,312 KB
testcase_28 AC 2,198 ms
72,152 KB
testcase_29 AC 2,147 ms
71,976 KB
testcase_30 AC 2,386 ms
72,176 KB
testcase_31 AC 244 ms
54,248 KB
testcase_32 AC 248 ms
54,268 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