#P9699. [GDCPC2023] X Equals Y

[GDCPC2023] X Equals Y

题目描述

For positive integers XX and b2b \geq 2, define f(X,b)f(X,b) as a sequence which describes the base-bb representation of XX, where the ii-th element in the sequence is the ii-th least significant digit in the base-bb representation of XX. For example, f(6,2)={0,1,1}f(6, 2) = \{0, 1, 1\}, while f(233,17)={12,13}f(233, 17) = \{12, 13\}.

Given four positive integers xx, yy, AA and BB, please find two positive integers aa and bb satisfying:

  • 2aA2 \leq a \leq A
  • 2bB2 \leq b \leq B
  • f(x,a)=f(y,b)f(x, a) = f(y, b)

输入格式

There are multiple test cases. The first line of the input contains an integer TT (1T1031 \leq T \leq 10^3) indicating the number of test cases. For each test case:

The first line contains four integers xx, yy, AA and BB (1x,y1091 \leq x,y \leq 10^9, 2A,B1092 \leq A,B \leq 10^9).

It's guaranteed that there are at most 5050 test cases satisfying max(x,y)>106\max(x, y) > 10^6.

输出格式

For each test case, if valid positive integers aa and bb do not exist, output NO\texttt{NO} in one line.

Otherwise, first output YES\texttt{YES} in one line. Then in the next line, output two integers aa and bb separated by a space. If there are multiple valid answers, you can output any of them.

题目大意

【题目描述】

对于正整数 XXb2b \geq 2,定义 f(X,b)f(X,b) 为一个描述了 XXbb 进制表示下的序列,其中序列的第 ii 个元素表示 XXbb 进制表示下从低到高第 ii 位的值。例如,f(6,2)={0,1,1}f(6, 2) = \{0, 1, 1\},而 f(233,17)={12,13}f(233, 17) = \{12, 13\}

给定的四个正整数 xxyyAABB,请找到两个正整数 aabb,同时满足:

  • 2aA2 \leq a \leq A
  • 2bB2 \leq b \leq B
  • f(x,a)=f(y,b)f(x, a) = f(y, b)

【输入格式】

有多组测试数据。第一行输入一个整数 TT1T1031 \leq T \leq 10^3)表示测试数据组数。对于每组测试数据:

第一行输入四个整数 xxyyAABB1x,y1091 \leq x,y \leq 10^92A,B1092 \leq A,B \leq 10^9)。

保证至多只有 5050 组测试数据满足 max(x,y)>106\max(x, y) > 10^6

【输出格式】

对于每组测试数据,如果不存在合法的正整数 aabb,则输出一行一个字符串 NO\texttt{NO}

否则,首先输出一行一个字符串 YES\texttt{YES}。下一行输出两个由单个空格分隔的整数 aabb。如果有多种合法答案,您可以输出任意一种。

6
1 1 1000 1000
1 2 1000 1000
3 11 1000 1000
157 291 5 6
157 291 3 6
10126 114514 789 12345
YES
2 2
NO
YES
2 10
YES
4 5
NO
YES
779 9478