結果
| 問題 |
No.1791 Repeat Multiplication
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-26 14:08:27 |
| 言語 | Scala(Beta) (3.6.2) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 767 bytes |
| コンパイル時間 | 16,071 ms |
| コンパイル使用メモリ | 269,196 KB |
| 実行使用メモリ | 72,668 KB |
| 最終ジャッジ日時 | 2025-03-13 02:39:33 |
| 合計ジャッジ時間 | 20,728 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 1 -- * 2 |
| other | -- * 32 |
ソースコード
import sun.management.counter.LongArrayCounter
import scala.annotation.tailrec
import 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 then
count(value * multiplier) += current
update(current, value, multiplier + 1)
for i <- 1 to n do
update(count(i), i, 2)
val result = Array.fill(q){0L}
for (x, i) <- query.zipWithIndex do
val left = count(x)
var right = 0L
for j <- 1 to n / x do
right += count(j)
result(i) = left * right
println(result.mkString("\n"))