codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1110C.md (2204B)


      1 Source: https://codeforces.com/problemset/problem/1110/C
      2 
      3 C. Meaningless Operations
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Can the greatest common divisor and bitwise operations have anything in common? It is time to answer this question.
     22 
     23 Suppose you are given a positive integer $a$. You want to choose some integer $b$ from $1$ to $a - 1$ inclusive in such a way that the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers $a \oplus b$ and $a \ \gt \& \ \gt b$ is as large as possible. In other words, you'd like to compute the following function:
     24 
     25 $$f(a) = \max_{0 \lt b \lt a}{gcd(a \oplus b, a \ \gt \& \ \gt b)}.$$
     26 
     27 Here $\oplus$ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR), and $\&$ denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
     28 
     29 The greatest common divisor of two integers $x$ and $y$ is the largest integer $g$ such that both $x$ and $y$ are divided by $g$ without remainder.
     30 
     31 You are given $q$ integers $a_1, a_2, \ldots, a_q$. For each of these integers compute the largest possible value of the greatest common divisor (when $b$ is chosen optimally).
     32 
     33 Input
     34 
     35 The first line contains an integer $q$ ($1 \le q \le 10^3$) — the number of integers you need to compute the answer for.
     36 
     37 After that $q$ integers are given, one per line: $a_1, a_2, \ldots, a_q$ ($2 \le a_i \le 2^{25} - 1$) — the integers you need to compute the answer for.
     38 
     39 Output
     40 
     41 For each integer, print the answer in the same order as the integers are given in input.
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 3
     49 2
     50 3
     51 5
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 3
     58 1
     59 7
     60 ```
     61 
     62 Note
     63 
     64 For the first integer the optimal choice is $b = 1$, then $a \oplus b = 3$, $a \ \gt \& \ \gt b = 0$, and the greatest common divisor of $3$ and $0$ is $3$.
     65 
     66 For the second integer one optimal choice is $b = 2$, then $a \oplus b = 1$, $a \ \gt \& \ \gt b = 2$, and the greatest common divisor of $1$ and $2$ is $1$.
     67 
     68 For the third integer the optimal choice is $b = 2$, then $a \oplus b = 7$, $a \ \gt \& \ \gt b = 0$, and the greatest common divisor of $7$ and $0$ is $7$.