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 isP_MR(t) for i in 0...4 return true if dfs(w,h,y+$vy[i],x+$vx[i]) end return false end def powmod(a,b,m) result = 1 while b>0 result = (result*a)%m if b&1==1 a = (a*a)%m b >>= 1 end return result end # https://ja.wikipedia.org/wiki/%E3%83%9F%E3%83%A9%E3%83%BC%E2%80%93%E3%83%A9%E3%83%93%E3%83%B3%E7%B4%A0%E6%95%B0%E5%88%A4%E5%AE%9A%E6%B3%95 def isP_MR(q) k = 1000 # return Prime.prime?(q) if q<10000000 return true if q==2 return false if q<2 return false if q&1==0 d = q-1 while d&1==0 d>>=1 end # r = [q-1,(2*Math.log(q)**2).floor].min for i in 0...k a = rand(q-2)+1 t = d y = powmod(a,t,q) while t!=q-1 && y!=1 && y!=q-1 y = (y*y) % q t <<= 1 end if y!=q-1 && t&1==0 return false end end return true 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