結果
| 問題 |
No.1312 Snake Eyes
|
| コンテスト | |
| ユーザー |
yuruhiya
|
| 提出日時 | 2020-12-13 11:31:58 |
| 言語 | Crystal (1.14.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,150 bytes |
| コンパイル時間 | 11,580 ms |
| コンパイル使用メモリ | 297,480 KB |
| 実行使用メモリ | 13,760 KB |
| 最終ジャッジ日時 | 2024-06-30 21:49:09 |
| 合計ジャッジ時間 | 16,263 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 WA * 2 TLE * 1 -- * 49 |
ソースコード
lib C
fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end
class String
def to_i64
C.strtoll(self, nil, 10)
end
end
struct Int
def prime_factor : Array(Tuple(self, Int32))
result = Array(Tuple(self, Int32)).new
n = self
typeof(self).new(2).upto(Math.sqrt(self).ceil) do |x|
count = 0
while n % x == 0
n //= x
count += 1
end
result << {x, count} if count > 0
end
result << {n, 1} if n != 1
result
end
def divisors : Array(self)
result = Array(self).new
typeof(self).new(1).upto(self) do |x|
break if x * x > self
result << x if self % x == 0
end
(0...result.size).reverse_each do |i|
result << self // result[i] if result[i] * result[i] < self
end
result
end
end
n = read_line.to_i64
ans = n - 1
n.divisors.each do |d|
if d <= Math.sqrt(n)
(d + 1..n).each do |x|
val = 1i64
while val <= n // d
ans = {ans, x}.min if n // d == val
val = val * x + 1
end
end
else
d.divisors.each do |a|
b = n // a - 1
ans = {ans, b}.min if a < b
end
end
end
puts ans
yuruhiya