Fixed Share value calculation

Fixed Share value calculation to meet with the pool
Included more code optimizations from SunnyKing's and Mikaekh's
primecoin client
Change the way how chains are counted.