結果

問題 No.757 チャンパーノウン定数 (2)
コンテスト
ユーザー ciel
提出日時 2020-08-23 13:29:22
言語 Crystal
(1.19.1)
コンパイル:
crystal build -Donline_judge -o a.out --release --no-debug _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 841 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 997 ms
コンパイル使用メモリ 237,740 KB
最終ジャッジ日時 2026-03-21 07:18:12
合計ジャッジ時間 1,893 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Showing last frame. Use --error-trace for full trace.

In Main.cr:6:26

 6 | 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(&)

ソースコード

diff #
raw source code

#!/usr/bin/env crystal
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
0