結果
| 問題 | 
                            No.718 行列のできるフィボナッチ数列道場 (1)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hirakich1048576
                         | 
                    
| 提出日時 | 2016-07-10 19:01:38 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 615 bytes | 
| コンパイル時間 | 296 ms | 
| コンパイル使用メモリ | 7,680 KB | 
| 実行使用メモリ | 12,416 KB | 
| 最終ジャッジ日時 | 2024-09-14 13:59:01 | 
| 合計ジャッジ時間 | 3,552 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | RE * 3 | 
| other | RE * 20 | 
コンパイルメッセージ
Main.rb:2: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument Main.rb:6: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument Main.rb:16: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument Syntax OK
ソースコード
def div_ceil (l, r)
	q = l / r ; q += 1 if l % r != 0 ; q
end
def binpow (x)
	if x == 0 then
		1
	else
		lowest = ((x % 2 == 0) ? 1 : $kd)
		lowest * (binpow(x / 2) ** 2)
	end
end
def calc (n)
	($a - 1) * binpow(n) + (binpow(n + 1) - 1) / $k
end
def init_r
	maybe = 1
	maybe *= 2 while calc(maybe) < $m
	maybe
end
def solve
	if $k == 0 then
		return $m - $a
	end
	$kd = $k + 1
	l = 0
	r = init_r
	while l != r
		if calc((l + r) / 2) < $m then
			l = div_ceil(l + r, 2)
		else
			r = (l + r) / 2
		end
	end
	l
end
$m     = gets.chomp.to_i(10)
$a, $k = gets.chomp.split(' ').map{|e| e.to_i(10)}
puts solve
            
            
            
        
            
hirakich1048576