結果
| 問題 |
No.1339 循環小数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-15 23:05:43 |
| 言語 | Ruby (3.4.1) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 882 bytes |
| コンパイル時間 | 292 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 586,496 KB |
| 最終ジャッジ日時 | 2024-11-26 17:13:24 |
| 合計ジャッジ時間 | 53,445 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 10 TLE * 10 MLE * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
class SPFPrime
def initialize(max)
@spf = (0..max).to_a
sqmax = Math.sqrt(max).ceil
4.step(sqmax, 2) { |i| @spf[i] = 2 }
3.step(sqmax, 2) { |i| (i*i).step(max, i) { |j| @spf[j] = i if @spf[j] == j } if @spf[i] == i }
end
def prime?(n); @spf[n] == n; end
def each; (2..max).each { |i| yield i if @spf[i] == i }; end
def factorize(n); fs = []; while n > 1; f = @spf[n]; fs << f; n /= f; end; fs; end
end
T = gets.to_i
testcases = Array.new(T) {
n = gets.to_i
n /= 2 while n % 2 == 0
n /= 5 while n % 5 == 0
n
}
prime = SPFPrime.new testcases.max
testcases.each do |n|
len = 1
prime.factorize(n).tally.each do |(p, e)|
count = 1
repnov = 9 % p
until repnov == 0
repnov = (repnov * 10 + 9) % p
count += 1
end
count *= p ** (e - 1)
len = len.lcm(count)
end
puts len
end