C = 326! / [2!(326 - 2)!] = 326! / (2!*324!) = (326*325*324!) / (2!*324!) = 326*325 / 2! =
= 326*325 / 2 = 52975
Your answer is 52975 handshakes.
Your second question is a bit different because in the groups of answers we would count, for example, student 3 giving a treat to student 18 AND student 18 giving a treat to student 3. So in the list of groups we would have, among others:
{(1,2), (2,1), (3,18), (18,3), (54,187), (187,54),... etc.}
So in this case the order DOES matter, so it's a permutation case, and again there is no repetition because a student cannot give himself or herself a treat, so groups like (7,7) or (278,278) do not count. The formula for this case is:
m! / (m - n)!
m = total number of elements, which is 326
n = total number of elements per group, which is 2
m! / (m - n)! = 326! / (326 - 2)! = 326*325*324! / 324! = 326*325 = 105950
That's your answer: 105950 treats exchanged.
I hope this helps!