結果

問題 No.638 Sum of "not power of 2"
ユーザー 💕💖💞💕💖💞
提出日時 2018-04-05 21:59:19
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 11,966 ms
コンパイル使用メモリ 433,848 KB
実行使用メモリ 57,032 KB
最終ジャッジ日時 2024-04-30 18:14:21
合計ジャッジ時間 15,416 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 294 ms
56,884 KB
testcase_04 AC 295 ms
56,908 KB
testcase_05 AC 280 ms
56,808 KB
testcase_06 AC 280 ms
56,864 KB
testcase_07 AC 278 ms
56,748 KB
testcase_08 AC 274 ms
56,816 KB
testcase_09 AC 275 ms
56,780 KB
testcase_10 AC 279 ms
56,756 KB
testcase_11 AC 275 ms
56,832 KB
testcase_12 AC 281 ms
56,756 KB
testcase_13 AC 277 ms
56,892 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
         ^

ソースコード

diff #

import java.math.BigDecimal

fun main(args:Array<String>) {
  val n = readLine()!!.toBigDecimal()
  
  val m = ("1" + "0".repeat(18)).toBigDecimal()

  val bs = mutableSetOf<BigDecimal>()
  var tp = 1.toBigDecimal()
  stack@while(true) {
    if( tp > m ) break@stack
    //println(tp) 
    bs.add( tp )
    tp *= 2.toBigDecimal()
  }
  var x = 0.toBigDecimal()
  var control = false
  scan@while(true) {
    x++
    if( bs.contains(x) ) continue@scan
    val y = n - x
    if( !bs.contains(y) ) {
      control = true
      break@scan
    }
    if( x > n/2.toBigDecimal() ) break@scan
  }
  if( control )
    println("${x} ${n - x}")
  else 
    println("-1")
}
0