ran_by_Dipz's blog

By ran_by_Dipz, 81 minute(s) ago, In English

Hey everyone,

While solving Problem A (A Number Between Two Others), I noticed a lot of solutions get caught up thinking about prime factors or trying to construct specific test values for $$$z$$$.

Turns out, the entire problem collapses into a single inequality.

The Shortcut

Let $$$y = k \cdot x$$$. Since $$$y$$$ is divisible by $$$x$$$, $$$k \ge 2$$$.

We need a multiple of $$$x$$$, say $$$z = m \cdot x$$$, that lies between $$$x$$$ and $$$y$$$ and does not divide $$$y$$$.

This just means finding an integer $$$m$$$ between $$$1$$$ and $$$k$$$ where $$$k$$$ is not divisible by $$$m$$$:

  • If $$$k = 2$$$: No integer exists strictly between $$$1$$$ and $$$2$$$ $$$\to$$$ NO.

  • If $$$k \ge 3$$$: Always possible $$$\to$$$ YES.

So the answer is YES if and only if $$$k \gt 2$$$, which simply means: b - a > a (or b > 2 * a).

Code

```cpp
   #include <bits/stdc++.h>
   using namespace std;
   #define ll long long

   void solve(){
       ll a,b;
       cin>>a>>b;
       cout<<(b-a>a ? "YES\n" : "NO\n");
   }

   int main() {
       ios_base::sync_with_stdio(false);
       cin.tie(NULL);
       int t;
       cin>>t;
       while (t--) solve();
       return 0;
   }

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it