Extended count_electrons and N() function to calculate momenta of energy