解题思路:分情况讨论。k+1是素数的时候,如果2(k+1)>n+1那么一天就可以了,如果2(k+1)<=n+1说明有素数的倍数,那么需要两天。k+1不是素数的时候,根据伯特兰-切比雪夫定理利用第一天找到最大的一个素数,而且这个素数还在范围里,第二天全通知。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lf;
typedef unsigned long long ull;
typedef pair<ll,int>P;
const int inf = 0x7f7f7f7f;
const ll INF = 1e16;
const int N = 1e6+10;
const ull base = 131;
const ll mod = 1e9+7;
const double PI = acos(-1.0);
const double eps = 1e-4;
inline int read(){
int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';ch=getchar();}return x*f;}
inline string readstring(){
string str;char s=getchar();while(s==' '||s=='\n'||s=='\r'){
s=getchar();}while(s!=' '&&s!='\n'&&s!='\r'){
str+=s;s=getchar();}return str;}
int random(int n){
return (int)(rand()*rand())%n;}
void writestring(string s){
int n = s.size();for(int i = 0;i < n;i++){
printf("%c",s[i]);}}
ll fast_power(ll a,ll p){
ll ans = 1;
while(p){
if(p&1) ans = (ans*a)%mod;
p >>= 1;
a = (a*a)%mod;
}
return ans;
}
bool is_prime(ll n){
if(n < 2) return false;
for(ll i = 2;i*i <= n;i++){
if(n%i == 0) return false;
}
return true;
}
int main(){
srand((unsigned)time(NULL));
ll n,k;
cin >> n >> k;
if(is_prime(k+1)){
if(2*(k+1) > n+1) puts("1");
else puts("2");
}else {
puts("2");
}
return 0;
}