結果

問題 No.1200 お菓子配り-3
ユーザー 👑 箱星箱星
提出日時 2020-08-28 22:23:14
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,985 ms / 4,000 ms
コード長 1,674 bytes
コンパイル時間 13,796 ms
コンパイル使用メモリ 443,412 KB
実行使用メモリ 63,936 KB
最終ジャッジ日時 2024-04-30 23:54:09
合計ジャッジ時間 39,854 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
54,428 KB
testcase_01 AC 287 ms
54,384 KB
testcase_02 AC 310 ms
54,732 KB
testcase_03 AC 302 ms
54,832 KB
testcase_04 AC 303 ms
54,756 KB
testcase_05 AC 315 ms
54,824 KB
testcase_06 AC 304 ms
54,764 KB
testcase_07 AC 312 ms
54,812 KB
testcase_08 AC 327 ms
54,908 KB
testcase_09 AC 341 ms
54,888 KB
testcase_10 AC 313 ms
54,780 KB
testcase_11 AC 314 ms
54,832 KB
testcase_12 AC 437 ms
55,128 KB
testcase_13 AC 440 ms
54,880 KB
testcase_14 AC 432 ms
54,852 KB
testcase_15 AC 425 ms
54,996 KB
testcase_16 AC 420 ms
54,936 KB
testcase_17 AC 750 ms
59,676 KB
testcase_18 AC 942 ms
59,700 KB
testcase_19 AC 486 ms
55,032 KB
testcase_20 AC 1,439 ms
61,828 KB
testcase_21 AC 1,521 ms
61,836 KB
testcase_22 AC 1,647 ms
63,936 KB
testcase_23 AC 1,429 ms
61,676 KB
testcase_24 AC 1,442 ms
61,904 KB
testcase_25 AC 1,408 ms
61,804 KB
testcase_26 AC 1,428 ms
61,928 KB
testcase_27 AC 284 ms
54,220 KB
testcase_28 AC 1,985 ms
61,848 KB
testcase_29 AC 1,628 ms
61,756 KB
testcase_30 AC 1,609 ms
61,772 KB
testcase_31 AC 281 ms
54,224 KB
testcase_32 AC 279 ms
54,284 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
        val n2 = Math.abs(x - y)
        var d = 1
        while (d * d <= n1) {
            if (n1 % d == 0) {
                val a1 = d - 1L
                if (a1 >= 2 && n2 % (a1 - 1) == 0L) {
                    cand_a.add(a1)
                }
                val a2 = n1 / d - 1L
                if (a2 >= 2 && n2 % (a2 - 1) == 0L) {
                    cand_a.add(a2)
                }
            }
            d++
        }
        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