#P16399. [ECUSTPC 2026 Spring] 朝复习

    ID: 18413 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>贪心Special Judge最大公约数 gcd2026高校校赛

[ECUSTPC 2026 Spring] 朝复习

Background

:::epigraph Computer Science: Review (Computer Science: Go Over, known as ___ ) is something popular around the world. :::

Problem Description

This problem is unrelated to Problem H "Morning Review, Evening Review".

TSUCE (Time-Space Union of Coding Experts) is going to hold the TSUCE Programming Duel Cup, a head-to-head algorithm contest between two players.

The rules are as follows. Please pay attention to the meanings of nn and mm:

  • Each match is played between two players. In each match, there is exactly one winner, and there are no draws.
  • A match consists of one regulation period plus several overtime periods (possibly 00 overtime periods). The regulation period contains 2n2n rounds. Each overtime period contains 2m2m rounds. In each round, there is exactly one winner.
  • During regulation, the player who gets n+1n + 1 round wins will win the whole match, and the match ends immediately.
  • If there is still no winner after the 2n2n rounds of regulation (the score is n:nn:n), the match enters overtime. In a single overtime period, the player who gets m+1m + 1 round wins will win the whole match, and the match ends immediately.
  • If there is still no winner after one overtime period, the match enters the next overtime period, until a winner is decided.
  • The final score is the number of rounds each side wins in the whole match.

Unfortunately, scorekeeper Little T’s database broke. He only remembers the scores of all kk matches, but he does not remember the nn and mm related to the rules.

Please help him determine whether there exists a pair of valid positive integers nn and mm such that all these scores are valid under this rule set.

Input Format

The first line contains an integer T (1≤T≤105)T \ (1 \le T \le 10^5), the number of testdata.

For each testdata, the first line contains an integer k (1≤k≤105)k \ (1 \le k \le 10^5), the number of recorded matches.

Then follow kk lines, each containing two integers aa and b (0≤a,b≤1018,∣a−b∣≥2)b \ (0 \le a, b \le 10^{18}, |a - b| \ge 2), representing the score of a match recorded in Little T’s database.

It is guaranteed that ∑k≤3×105\sum k \le 3 \times 10^5 over all testdata.

Output Format

For each testdata, if there exists a valid nn and mm such that all these scores are valid under this rule set, output one line with the string YES; otherwise output one line with the string NO.

Note that the judge is case-insensitive for YES and NO. In other words, if the answer is positive, outputs like yes, YES, Yes, YeS, etc. will all be accepted.

6
3
16 14
10 16
19 22
2
11 16
19 22
5
2 13
16 12
9 13
13 10
20 22
2
5 7
5 9
3
0 5
5 2
11 7
2
6 9
9 6
YES
YES
YES
NO
YES
YES

Hint

Sample 1 Explanation

For the 3rd testdata, we can find that n=12,m=3n = 12, m = 3 is a valid solution. Then the matches may go through the following process:

  • Match 1: 2:132:13. During regulation, player B first reaches n+1=13n + 1 = 13 wins and ends the match.
  • Match 2: 16:1216:12. Regulation ends in a 12:1212:12 tie. In the first overtime period, player A wins 4:04:0 and gets m+1=4m + 1 = 4 wins.
  • Match 3 and Match 4 end in regulation with scores 9:139:13 and 13:1013:10, respectively.
  • Match 5: Regulation ends in a 12:1212:12 tie. In both the first and second overtime periods, the score is 3:33:3, so the match reaches 18:1818:18 and enters the third overtime period. Finally, player B wins 4:24:2 in the third overtime period, and the final score is A 20:2220:22 B.

Translated by ChatGPT 5