COVID Handshake Problem

E · easyP · Verified PYQmath

Before the outbreak of coronavirus, a meeting took place in Wuhan. A person who attended had COVID-19 and everyone shook hands with everyone else exactly once. Given N people in the room, find the total number of handshakes. Input: First line = T (test cases). Each following line = N (number of people).

1<=T<=1000, 0<N<10\*\*6
Input
2
1
2
Output
0
1
Total handshakes = N\*(N-1)/2. Use long long to avoid overflow for large N.
1 person → 0 handshakes. 2 people → 1 handshake. Formula: N\*(N-1)/2
← Count Words in a StringCurtain Factory — Max Aqua Curtains in Any Box →
Report an issue with this question