結果

問題 No.1200 お菓子配り-3
ユーザー 👑 箱星箱星
提出日時 2020-08-28 22:20:29
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,835 ms / 4,000 ms
コード長 1,658 bytes
コンパイル時間 12,485 ms
コンパイル使用メモリ 436,908 KB
実行使用メモリ 80,336 KB
最終ジャッジ日時 2024-04-30 23:52:29
合計ジャッジ時間 36,861 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 242 ms
54,372 KB
testcase_01 AC 241 ms
54,172 KB
testcase_02 AC 268 ms
55,396 KB
testcase_03 AC 262 ms
55,268 KB
testcase_04 AC 283 ms
55,184 KB
testcase_05 AC 291 ms
55,460 KB
testcase_06 AC 272 ms
55,368 KB
testcase_07 AC 287 ms
55,468 KB
testcase_08 AC 307 ms
55,716 KB
testcase_09 AC 345 ms
56,068 KB
testcase_10 AC 285 ms
55,456 KB
testcase_11 AC 281 ms
55,272 KB
testcase_12 AC 448 ms
58,140 KB
testcase_13 AC 428 ms
57,764 KB
testcase_14 AC 394 ms
57,592 KB
testcase_15 AC 415 ms
57,584 KB
testcase_16 AC 403 ms
57,740 KB
testcase_17 AC 725 ms
63,756 KB
testcase_18 AC 921 ms
68,020 KB
testcase_19 AC 456 ms
57,768 KB
testcase_20 AC 1,353 ms
76,296 KB
testcase_21 AC 1,372 ms
76,212 KB
testcase_22 AC 1,528 ms
80,336 KB
testcase_23 AC 1,330 ms
76,308 KB
testcase_24 AC 1,381 ms
76,324 KB
testcase_25 AC 1,367 ms
76,172 KB
testcase_26 AC 1,328 ms
76,192 KB
testcase_27 AC 237 ms
54,224 KB
testcase_28 AC 1,835 ms
65,948 KB
testcase_29 AC 1,491 ms
72,152 KB
testcase_30 AC 1,534 ms
71,952 KB
testcase_31 AC 246 ms
54,272 KB
testcase_32 AC 252 ms
54,232 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_cand_a = mutableSetOf<Long>()
        val n1 = x + y
        var d = 1
        while (d * d <= n1) {
            if (n1 % d == 0) {
                cand_cand_a.add(d - 1L)
                cand_cand_a.add(n1 / d - 1L)
            }
            d++
        }
        val n2 = Math.abs(x - y)
        val cand_a = mutableSetOf<Long>()
        for (a in cand_cand_a) {
            if (a >= 2 && n2 % (a - 1) == 0L) {
                cand_a.add(a)
            }
        }
        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