結果
問題 |
No.1747 Many Formulae 2
|
ユーザー |
|
提出日時 | 2022-01-25 00:28:02 |
言語 | Scala(Beta) (3.6.2) |
結果 |
AC
|
実行時間 | 819 ms / 2,000 ms |
コード長 | 837 bytes |
コンパイル時間 | 12,735 ms |
コンパイル使用メモリ | 257,580 KB |
実行使用メモリ | 64,860 KB |
最終ジャッジ日時 | 2024-12-15 04:49:35 |
合計ジャッジ時間 | 27,617 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
import scala.annotation.tailrec import scala.io.StdIn.* def isPrime(value: Long): Boolean = @tailrec def isPrimeInner(p: Long): Boolean = if p * p > value then true else value % p != 0 && isPrimeInner(p + 1) if value <= 2 then value == 2 else isPrimeInner(2) def countExpression(digits: List[Int])(predicate: Long => Boolean): Int = def enumerate(rest: List[Int], confirmed: Long = 0, last: Long = 0): Int = rest match case Nil => if predicate(confirmed + last) then 1 else 0 case h::Nil => enumerate(Nil, confirmed, last * 10 + h) case h::t => enumerate(t, confirmed, last * 10 + h) + enumerate(t, confirmed + last * 10 + h, 0) enumerate(digits) @main def main = val expr = readLine().map(_.asDigit).toList val result = countExpression(expr){isPrime} println(result)