From the 1996 UF ACM High School Programming Competition

Choice Numbers

``There are choice cuts of beef, choice art, cars that are (at least according to Ferris Bueller) choice, so why are there no choice numbers?'' rants Larry Coro, a rather reversed, somewhat deranged mathematician.

This is typical for the Plaza, where people holding very strange views tend to gather around lunchtime. Perhaps they gather for the food, or perhaps the food is what shoves their minds off that delicate balance called sanity. You don't know; you don't care. What you care about is getting this crazy guy out of your face.

``So, I've come up with a neat way to put numbers on equal footing with beef,'' he says as you try your patented dodge-the-crazy-guy move. It doesn't work.

``All I need is a little computer help to find out just which ones are choice...''

Problem Statement

Write a program to determine which numbers of a given set are considered choice and which are not.

A number is considered choice if one of its factors is also the number of factors of the number. For instance, the number 24 has 8 factors: 1, 2, 3, 4, 6, 8, 12, 24. Eight is itself one of those factors, so 24 is considered choice. Eleven is not choice, as 2, the number of factors, is not a factor of 11.

A number's factors are all the positive integers which evenly divide the number, giving no remainder.

Notes

The input will consist of a sequence of positive integers less than 32,767 and a terminal 0. Obviously, the last 0 should not be processed. There will be at most 10 numbers given, not including the zero.

The output must give all the choice numbers in one block and all the non-choice numbers in another. Order is not important.

Examples

Example 1:
Enter numbers to test: 20 21 24 11 2 0
Choice numbers: 24, 2
Non-choice numbers: 20, 21, 11

Example 2:
Enter numbers to test: 1946 35 200 0
No choice numbers were given.
Non-choice numbers: 1946, 35, 200


Grader's Test Data

Example 3:
Enter numbers to test: 2 8 128 7 48 0
Choice numbers: 2, 8, 128
Non-choice numbers: 7, 48

Example 4:
Enter numbers to test: 4 16 32 512 24 0
Choice numbers: 24
Non-choice numbers: 4, 16, 32, 512

Example 5:
Enter numbers to test: 18 227 9 1048 32104 502 503 504 505 506 0
Choice numbers: 18, 9, 1048, 32104, 504
Non-choice numbers: 227, 502, 503, 505, 506


Solutions

C solution by Jason Riedy:
choice.c