solve 1024Bpr problem of GiangTran