Helper functions for PE and other math problems