Program to calculate perfect numbers