Mr. P retired and invited his math students and his computer students to his retirement party.
Mr. P shook hands with all his guests.
Among his guests, his math students shook hands with each other, and his computer students shook hands with each other; but the math students and computer students simply greeted one another with a nod of the head.

One hundred twenty-three handshakes were exchanged at the party.
No math student was also a computer student.

How many people were at the party (including old Mr. P) if at least 3 math students and at least 3 computer students attended?




Solution:

The answer is 22 people, including Mr. P, 9 members of one class, and 12 members of the other group.

Mr. P shook hands with all 21 students.
The nine math students shook hands with the other 8 math students for
a total of 36 handshakes (9 x 8 / 2).
The 12 computer students shook hands with the other 11 computer students for
a total of 66 handshakes (12 x 11 / 2).

To solve this problem,
let c = number of computer students who came to the party.
Let m = the number of math students who attended.
The number of handshakes which take place among a group of n people can be determined by the formula for the combinations of n things taken r at a time, where r = 2.
The formula nCr = (n!) / (r!((n - r)!))

Number of people Number of Handshakes
Mr. P (1) c + m
m math students (m!) / ((m - 2)! x 2!) = (1/2)m(m - 1)
c computer students (c!) / ((c - 2)! x 2!) = (1/2)c(c - 1)

Totaling the three columns above, the number of handshakes =
c + m + (1/2)c^2 - (1/2)c + (1/2)m^2 - (1/2)m.
Set this equal to 123 and simplify to get the following:

c^2 + c + m^2 + m = 246.

I wrote a computer program in C++ to solve this problem.
Listed below is the nested loop which checks this condition:

for (int m = 0; m<=240; m++) for (int c=m; c<=240; c++) if ((c*c + c + m*m + m) == 246) cout << "computer kids = " << c << " and math kids = " << m << endl;

When I ran the program, I discovered two solutions to the problem:
2 math students and 15 computer students and
9 math students and 12 computer students.
So I added the additional clue about having at least 3 students from each class at the party.



Correctly solved by:

1. Tom Marino Winchester, VA
2. Ankit Garg Fremont, CA
3. Richard Mocarski Winchester, VA
4. Chip Crawford Winchester, VA
5. Court Pifer Winchester, VA
6. Jon Pence Winchester, VA
7. Jia Ran Rome, Italy