Prolog (SWI), 5548 bytes
Y+X:-X=<Y;X mod Y>0,Y+1+X.
\X:-X>1,2+X,- \XX+1/\ \X=:=X+1\X<1.
-7 thanks to Jo King
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack ExchangeY+X:-X=<Y;X mod Y>0,Y+1+X.
\X:-X>1,2+X,- \XX+1/\ \X=:=X+1\X<1.
-7 thanks to Jo King