Replaced the kronecker sum algorithm with an even more efficient one that loops from 1 to N rather than 1 to N^p