require'prime' m=2048 l=(0..n=gets.to_i).map{{0=>0}} (2..n).each{|i|r=s=0;t=1;Prime.each(i){|q|i%q>0&&(r=q;s|=t);t*=2};l[r][s%m]=i} p l.inject([0]*m){|f,k|(0...m).map{|x|k.map{|s,i|s>(x&s)?0:f[x^s]+i}.max}}.max