AtCoder Regular Contest 164
翻译中…
Problem Statement
翻译中…
You are given integers $N$ and $K$. Is it possible to express $N$ as the sum of exactly $K$ numbers of the form $3^m$ ($m$ is a non-negative integer)? In other words, is there a sequence of non-negative integers $(m_1, m_2,\ldots, m_K)$ such that:
翻译中…
$N= 3^{m_1}+3^{m_2}+...+3^{m_K}$?
翻译中…
You are given $T$ test cases. Answer each of them.
翻译中…
Constraints
翻译中…
$1 \leq T \leq 10^5$$1 \leq K \leq N \leq 10^{18}$- All input values are integers.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
翻译中…
Each test case, $\mathrm{case}_i (1\leq i \leq T)$, is in the following format:
翻译中…
N K
翻译中…
Output
翻译中…
Print $T$ lines. The $i$-th line should contain Yes if there is a sought sequence of non-negative integers for the $i$-th test case, and No otherwise.
翻译中…
样例
Input #1
4
5 3
17 2
163 79
1000000000000000000 1000000000000000000
Output #1
Yes
No
Yes
Yes
For the first test case, we have $5=3^1+3^0+3^0$, so the condition in question is satisfied.
For the second test case, there is no sequence of non-negative integers $(m_1, m_2)$ such that $17=3^{m_1}+3^{m_2}$, so the condition in question is not satisfied.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。