PRIME: Planning and Retrieval-Integrated Memory for Enhanced Reasoning