Rubyで2分探索 ref: http://qiita.com/items/74eb27bb98641ba05b2f