首先引用一下百度百科上面贴的定理
#include <iostream> #include <algorithm> #include <string> #include <cstring> #include <map> #include <set> #include <deque> #include <queue> #include <vector> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> #define PI acos(-1) using namespace std; typedef long long ll; typedef pair<int,int> pii; const ll maxn = 1e6+10; double eps = 1e-8; ll N,K; bool is_prime(ll x){ for(ll i = 2;i*i <= x;i++) if(x%i ==0) return false; return true; } int main(){ cin>>N>>K; N++,K++; if(is_prime(K) && 2LL*K>N) puts("1"); else puts("2"); return 0; }