qinhe algorithm