結果

問題 No.2324 Two Countries within UEC
ユーザー simansiman
提出日時 2023-06-06 18:43:23
言語 Ruby
(3.3.0)
結果
AC  
実行時間 633 ms / 2,000 ms
コード長 790 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 11,124 KB
実行使用メモリ 15,460 KB
最終ジャッジ日時 2023-09-09 06:26:07
合計ジャッジ時間 15,377 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 623 ms
15,404 KB
testcase_01 AC 516 ms
15,180 KB
testcase_02 AC 132 ms
15,180 KB
testcase_03 AC 354 ms
15,304 KB
testcase_04 AC 553 ms
15,132 KB
testcase_05 AC 176 ms
15,172 KB
testcase_06 AC 272 ms
15,224 KB
testcase_07 AC 145 ms
15,180 KB
testcase_08 AC 511 ms
15,376 KB
testcase_09 AC 507 ms
15,256 KB
testcase_10 AC 423 ms
15,224 KB
testcase_11 AC 633 ms
15,404 KB
testcase_12 AC 256 ms
15,204 KB
testcase_13 AC 230 ms
15,080 KB
testcase_14 AC 132 ms
15,356 KB
testcase_15 AC 162 ms
15,204 KB
testcase_16 AC 313 ms
15,292 KB
testcase_17 AC 263 ms
15,180 KB
testcase_18 AC 185 ms
15,368 KB
testcase_19 AC 411 ms
15,460 KB
testcase_20 AC 148 ms
15,452 KB
testcase_21 AC 479 ms
15,348 KB
testcase_22 AC 539 ms
15,200 KB
testcase_23 AC 242 ms
15,400 KB
testcase_24 AC 538 ms
15,204 KB
testcase_25 AC 498 ms
15,364 KB
testcase_26 AC 299 ms
15,392 KB
testcase_27 AC 298 ms
15,200 KB
testcase_28 AC 298 ms
15,180 KB
testcase_29 AC 298 ms
15,420 KB
testcase_30 AC 295 ms
15,124 KB
testcase_31 AC 77 ms
15,088 KB
testcase_32 AC 77 ms
15,284 KB
testcase_33 AC 76 ms
15,152 KB
testcase_34 AC 77 ms
15,004 KB
testcase_35 AC 76 ms
15,224 KB
testcase_36 AC 77 ms
15,252 KB
testcase_37 AC 76 ms
15,056 KB
testcase_38 AC 77 ms
15,276 KB
testcase_39 AC 76 ms
15,268 KB
testcase_40 AC 76 ms
15,044 KB
testcase_41 AC 77 ms
15,276 KB
testcase_42 AC 76 ms
15,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:3: warning: assigned but unused variable - ans
Syntax OK

ソースコード

diff #

N, M, P, Q = gets.split.map(&:to_i)

ans = 0

Q.times do
  x, f = gets.split.map(&:to_i)

  if x % P == 0
    if f == 0
      puts M
    else
      puts 0
    end
  else
    t = f * x.pow(P - 2, P) % P

    if t == 0
      if P > M
        puts 0
      else
        ok = 1
        ng = M + 1

        while (ok - ng).abs >= 2
          k = (ok + ng) / 2

          if P * k <= M
            ok = k
          else
            ng = k
          end
        end

        puts ok
      end
    else
      if t > M
        puts 0
      else
        ok = 1
        ng = M + 2

        while (ok - ng).abs >= 2
          k = (ok + ng) / 2

          if P * (k - 1) + t <= M
            ok = k
          else
            ng = k
          end
        end

        puts ok
      end
    end
  end
end
0