#include #include #include #include #include using namespace std; int main(){ const int M = 200; int dd[] = {0, -1, 0, 1, 0}; bool npr[M + 1] = {true, true}; for(int i = 2; i <= M; ++i){ if(!npr[i]){ for(int j = i * 2; j <= M; j += i){ npr[j] = true; } } } string s; cin >> s; int n; if(s.size() > 2){ n = 50; } else{ n = strtol(s.c_str(), 0, 10); } if(n > 50){ n = 50; } int ans; for(ans = 3; ; ++ans){ assert(ans < n); vector vis(n + 1); vis[1] = 1; queue q; q.push(1); while(!q.empty()){ int y = (q.front() - 1) / ans; int x = (q.front() - 1) % ans; q.pop(); for(int i = 0; i < 4; ++i){ int ny = y + dd[i], nx = x + dd[i + 1]; if(ny < 0 || nx < 0 || nx >= ans){ continue; } int t = ny * ans + nx + 1; if(t > n || !npr[t] || vis[t]){ continue; } vis[t] = 1; q.push(t); } } if(vis[n]){ break; } } cout << ans << endl; }