Tidied up Egypt algorithm