結果

問題 No.237 作図可能性
ユーザー ともきともき
提出日時 2015-07-06 00:05:33
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 1,915 bytes
コンパイル時間 12,050 ms
コンパイル使用メモリ 256,936 KB
実行使用メモリ 65,452 KB
最終ジャッジ日時 2023-09-11 11:30:29
合計ジャッジ時間 46,072 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.io.StdIn.readLine
import scala.collection.mutable.PriorityQueue
import scala.annotation.tailrec

// PriorityQueue[Long]()(scala.math.Ordering.Long.reverse)
object Lib {
  // object Number {
  //   // @return Array length is equal to 'n'.
  //   //  Kth element of Array is true if K is prime else false.
  //   final def sieve(n : Int) : Array[Boolean] = {
  //     val isprime = Array.fill(n+1)(true)
  //     isprime(0) = false
  //     isprime(1) = false
  //     for(i <- 2 to Math.ceil(Math.sqrt(n.toDouble)).toInt;
  //         if isprime(i);
  //         j <- i*i to n by i){
  //       isprime(j) = false
  //     }
  //     isprime
  //   }
  //   // @return Array of primes that is less than or equal to n
  //   final def primes(n : Int) : Array[Int] =
  //     sieve(n).zipWithIndex.withFilter(_._1).map(_._2)
  // }
  object EnRich {
    implicit class AString(val self : String) extends AnyVal {
      def splitToIntArray = self.split(" ").map(_.toInt)
    }
    // implicit class PowerInt(val self : Int) extends AnyVal {
    //   def ** (n : Int) : Int = 
    // }
  }
}

import Lib.EnRich._
object Main {
  def solve(n : Long) : Int = {
    val fermat_numbers = List[Long](3, 5, 17, 257, 65537)
    def big(c : Set[Long],k : Long) : Set[Long] = {
      c.withFilter(_*k <= n).map(_*k) ++ c
    }
    val init = (0l to Math.ceil(Math.log(n)/Math.log(2)).toLong).
                 map((k) => Math.round(Math.pow(2,k)).toLong).toSet
    val drawables_in_n = fermat_numbers.foldLeft(init)(big(_,_)).filter((i) => 3 <= i && i <= n)
    println(drawables_in_n)
    drawables_in_n.size
    // println(drawables)
    // println(drawables)
    // drawables.foreach(println(_))
    // (1 to n).filter(drawables.contains(_)).foreach(println(_))
    // (3 to n).count(drawables.contains(_))
  }
  def main(args : Array[String]) : Unit = {
    val n = readLine().toLong
    println(solve(n))
  }
}
0