結果
問題 | No.1791 Repeat Multiplication |
ユーザー |
|
提出日時 | 2022-01-26 14:08:27 |
言語 | Scala(Beta) (3.6.2) |
結果 |
AC
|
実行時間 | 1,517 ms / 3,000 ms |
コード長 | 767 bytes |
コンパイル時間 | 17,349 ms |
コンパイル使用メモリ | 258,468 KB |
実行使用メモリ | 83,216 KB |
最終ジャッジ日時 | 2024-12-23 03:04:03 |
合計ジャッジ時間 | 61,431 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
import sun.management.counter.LongArrayCounterimport scala.annotation.tailrecimport scala.io.StdIn.*import scala.math.*@main def main =val Array(n, q) = readLine().split(' ').map(_.toInt)val query = Array.fill(q){readLine().toInt}val count = Array.fill(n + 1){0}count(1) = 1@tailrec def update(current: Int, value: Int, multiplier: Int): Unit =if value * multiplier <= n thencount(value * multiplier) += currentupdate(current, value, multiplier + 1)for i <- 1 to n doupdate(count(i), i, 2)val result = Array.fill(q){0L}for (x, i) <- query.zipWithIndex doval left = count(x)var right = 0Lfor j <- 1 to n / x doright += count(j)result(i) = left * rightprintln(result.mkString("\n"))