According to ancient Greek numerology, every number may be clasified as deficient, abundant, or perfect. These classifications are based on the sum of the factors (excluding the number itself). Thus, 9 is deficient (1+3 = 4 < 9), 12 is abundant (1+2+3+4+6 = 16 > 12), and 6 is perfect (1+2+3 = 6 = 6). The perfect numbers are the interesting ones. The exercise is to write an application where the user provides a seed number, and the application finds the next perfect number. Here is a list of the first 8 perfect numbers:
What's nice about this exercise is that it is a nice distraction from the boring plumbing-type coding required to get the application working. This happens several days into the class, so it provides a great outlet. Inevitably, students start doing research and get caught up in this topic. There is a great entry that describes the origins of perfect numbers on the Wikipedia site.
As much as I'd like to take credit for this, it came from an exercise in my first Pascal programming class. Dr. Head had us create lists of numbers that were perfect. On the Apple ][e, finding 496 took about 5 minutes. A simple, non-optimzed Java console application finds the first 4 almost instantly, and takes about 20 minutes to find the 5th. This is always a fun topic.