結果
| 問題 | No.757 チャンパーノウン定数 (2) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-23 13:43:51 |
| 言語 | Crystal (1.19.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 955 bytes |
| 記録 | |
| コンパイル時間 | 980 ms |
| コンパイル使用メモリ | 237,764 KB |
| 最終ジャッジ日時 | 2026-03-21 07:20:13 |
| 合計ジャッジ時間 | 1,364 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Showing last frame. Use --error-trace for full trace.
In Main.cr:8:26
8 | n=BigInt.new(s.not_nil!,base: base)+(starting-2)
^
Error: expected argument 'base' to 'BigInt.new' to be Int32, not BigInt
Overloads are:
- BigInt.new(str : String, base : Int32 = 10)
- BigInt.new(num : Int::Primitive)
- BigInt.new(num : Float::Primitive)
- BigInt.new(num : BigFloat)
- BigInt.new(num : BigDecimal)
- BigInt.new(num : BigRational)
- BigInt.new(num : BigInt)
- BigInt.new(mpz : LibGMP::MPZ)
- BigInt.new()
- BigInt.new(&)
ソースコード
#!/usr/bin/env crystal
lib C;fun strtoll(s: UInt8*,p: UInt8*,b: Int32): Int64;end
class String;def to_i64;C.strtoll(self,nil,10);end;end
require "big"
starting=1
base=BigInt.new(gets.not_nil!)
while (s=gets)!=nil
n=BigInt.new(s.not_nil!,base: base)+(starting-2)
digits=1
expbase=BigInt.new("1")
if false
while (x=expbase*(digits*(base-1)))<=n
digits+=1
expbase*=base
n-=x
end
else
if false
while digits*base**digits-(base**digits-1)//(base-1)<=n
digits+=1
end
elsif false
digits=1+(s.not_nil!.size.downto(0).find{|digits|
z=base**digits;z*digits-(z-1)//(base-1)<=n
}||0)
else
digits=(1..s.not_nil!.size).bsearch{|digits|
z=base**digits;z*digits-(z-1)//(base-1)>n
}||s.not_nil!.size
end
expbase=base**(digits-1)
n-=(digits-1)*expbase-(expbase-1)//(base-1)
end
num=expbase+n//digits
d=digits-1-n%digits
if false
d.times{num//=base}
puts num%base
else
puts num.to_s(base)[-d-1]
end
end