require"prime" N=20000 dp=Array.new(N+1) dp[0]=0 temp=0 Prime.each(N/2){|p| (N-p).downto(0){|k| next unless dp[k] temp=k+p unless dp[temp] dp[temp]=dp[k]+1 else dp[temp]=dp[k]+1 if dp[k]+1>dp[temp] end } } p dp[gets.to_i]||-1