結果

問題 No.492 IOI数列
ユーザー koyumeishikoyumeishi
提出日時 2017-03-10 23:27:05
言語 Ruby
(3.3.0)
結果
AC  
実行時間 73 ms / 1,000 ms
コード長 1,214 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 11,256 KB
実行使用メモリ 15,316 KB
最終ジャッジ日時 2023-09-06 14:20:00
合計ジャッジ時間 3,066 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
15,048 KB
testcase_01 AC 71 ms
15,104 KB
testcase_02 AC 72 ms
15,268 KB
testcase_03 AC 73 ms
15,248 KB
testcase_04 AC 68 ms
15,280 KB
testcase_05 AC 67 ms
15,236 KB
testcase_06 AC 67 ms
15,024 KB
testcase_07 AC 68 ms
15,080 KB
testcase_08 AC 72 ms
15,032 KB
testcase_09 AC 70 ms
15,048 KB
testcase_10 AC 71 ms
15,272 KB
testcase_11 AC 73 ms
15,272 KB
testcase_12 AC 69 ms
15,132 KB
testcase_13 AC 69 ms
15,148 KB
testcase_14 AC 73 ms
15,044 KB
testcase_15 AC 68 ms
15,200 KB
testcase_16 AC 71 ms
15,316 KB
testcase_17 AC 67 ms
15,112 KB
testcase_18 AC 68 ms
15,312 KB
testcase_19 AC 68 ms
15,204 KB
testcase_20 AC 71 ms
15,148 KB
testcase_21 AC 69 ms
15,316 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

mod1 = 10**9 + 7
mod2 = 101010101010101010101


n = gets.to_i

if n == 1 then
  puts 1
  puts 1
else
  m = n
  n = m-1
  res = [1,0,0,1]

  mat = [100,1,0,1]
  while n != 0 do 
    if( n%2 == 1 ) then
      res = [ mat[0] * res[0] + mat[1] * res[2], mat[0] * res[1] + mat[1] * res[3],
              mat[2] * res[0] + mat[3] * res[2], mat[2] * res[1] + mat[3] * res[3] ]
      res = res.map{|x| x % mod1 }
    end
    mat = [ mat[0] * mat[0] + mat[1] * mat[2], mat[0] * mat[1] + mat[1] * mat[3],
             mat[2] * mat[0] + mat[3] * mat[2], mat[2] * mat[1] + mat[3] * mat[3] ]
    mat = mat.map{|x| x%mod1 }
    n /= 2
  end
  puts (res[0] + res[1]) % mod1


  n = m-1
  res = [1,0,0,1]
  mat = [100,1,0,1]
  while n != 0 do 
    if( n%2 == 1 ) then
      res = [ mat[0] * res[0] + mat[1] * res[2], mat[0] * res[1] + mat[1] * res[3],
              mat[2] * res[0] + mat[3] * res[2], mat[2] * res[1] + mat[3] * res[3] ]
      res = res.map{|x| x % mod2 }
    end
    mat = [ mat[0] * mat[0] + mat[1] * mat[2], mat[0] * mat[1] + mat[1] * mat[3],
             mat[2] * mat[0] + mat[3] * mat[2], mat[2] * mat[1] + mat[3] * mat[3] ]
    mat = mat.map{|x| x%mod2 }
    n /= 2
  end
  puts (res[0] + res[1]) % mod2
end
0