Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
The operation can only make smaller or keep it the same. There is no way to multiply anything back in.
After one operation, the new value is , where divides . So the new value is also a divisor of the old .
After many operations, you have divided the original by some product of chosen divisors. The final value must still divide the original .
If divides , you can finish in one move: choose , then .
So the whole problem is just checking whether . No factorization, no simulation, no heroic nonsense.
Key Observation
Each operation divides the current value of by some divisor of it. That means the operation never introduces new prime factors, never increases , and never does anything fancy. It only removes factors from .
Suppose the original value is . If we do several operations with chosen values , then the final value is
Because every chosen divides the current value at that moment, this product divides the original . So the final number must be a divisor of the original .
Therefore, if we want to end at , we need:
or equivalently:
Why This Is Also Sufficient
Now assume divides . Then is an integer. Choose
Since divides , this divides . After one operation:
Done. One move. Clean.
Common Trap
Do not simulate all possible divisor choices. That is doing CrossFit for a doorbell problem. Since you are allowed to choose any divisor, the direct jump works whenever divides .
Also, checking is not enough. For example, , works, but , does not. The actual condition is divisibility.
Algorithm
For each test case:
YES.NO.Correctness Proof
We prove that the algorithm prints YES exactly when it is possible to make equal to .
First, suppose the algorithm prints YES. Then , so divides . Choose . Since divides , this is a valid operation. The new value becomes , so it is possible to make equal to .
Now suppose it is possible to make equal to . Each operation divides the current value by one of its divisors, so every value produced remains a divisor of the original . Therefore the final value must divide the original . Hence , so the algorithm prints YES.
Since both directions hold, the algorithm is correct.
Complexity
Each test case does one modulo operation.
Time complexity: per test case.
Memory complexity: .
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int x, y;
cin >> x >> y;
cout << (x % y == 0 ? "YES" : "NO") << '\n';
}
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int x, y;
cin >> x >> y;
cout << (x % y == 0 ? "YES" : "NO") << '\n';
}
}