require 'prime' N_MAX = 110 $mp = Array.new(N_MAX).map{Array.new(N_MAX,0)} $used = Array.new(N_MAX).map{Array.new(N_MAX,false)} $n = gets.chomp.to_i $vx = [1,0,-1,0] $vy = [0,1,0,-1] def dfs(w,h,y,x) return false if y<0 || x<0 || y>=h || x>=w return false if $used[y][x] $used[y][x] = true return false if $mp[y][x]==1e9 return true if $mp[y][x]==$n t = $mp[y][x] return false if Prime.prime?(t) for i in 0...4 return true if dfs(w,h,y+$vy[i],x+$vx[i]) end return false end if $n<100 for w in 3...$n h = $n/w + ( $n%w == 0 ? 0 : 1 ) for i in 0...N_MAX for j in 0...N_MAX $mp[i][j] = 1e9 if i