PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000400. Xóa số để tìm số bí mật (Deleting Numbers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xóa số để tìm số bí mật (Deleting Numbers)

Deleting Numbers

Source: Codeforces

Version: Phuoc Hung OJ Extended

Mode: interactive.

Problem Statement

An unknown integer x∈[1,n]x\in[1,n] is fixed by the judge. Initially a mutable set contains all numbers from 1 to nn. Discover xx using at most 10,000 operations:

  • A a, 1≤a≤n1\le a\le n: get the number of currently present elements divisible by aa, without changing the set.
  • B a, 2≤a≤n2\le a\le n: first get the number of present multiples of aa, then delete all of them except the hidden number xx, which is never deleted.
  • C a, 1≤a≤n1\le a\le n: assert that x=ax=a and terminate. This command is only allowed once.

Read one integer response after A and B, and flush every command. Invalid commands and wrong guesses fail.

PHOJ hidden input

A hidden test file contains n x. Only nn is sent initially; the interactor maintains the set and responds to operations.

Subtasks

  • Subtask 1 (20 points): 1≤x≤n≤1001\le x\le n\le100, at most 10,000 operations.
  • Subtask 2 (30 points): 1≤x≤n≤10 0001\le x\le n\le10\,000, at most 10,000 operations.
  • Subtask 3 (50 points): 1≤x≤n≤100 0001\le x\le n\le100\,000, at most 10,000 operations.

Example interaction

For n=10n=10 and hidden x=6x=6:

Judge: 10
Player: B 2
Judge: 5
Player: A 2
Judge: 1
Player: B 3
Judge: 3
Player: A 3
Judge: 1
Player: C 6

Explanation: B 2 reports 5 multiples and deletes 2,4,8,10, retaining 6. Hence A 2 returns 1. Next, B 3 sees 3,6,9, removes 3 and 9 and retains 6; A 3 returns 1. The interaction shown is only illustrative.