An arithmetic formula for the partition function