Friends Pairing Problem

code link https://ide.codingblocks.com/s/135770

What can be the problem with my code . I tested for 2 , 3 ,4 it was giving correct output.

The data type is unable to contain the answers for bigger test cases therefore storing garbage values. Using long data type instead of int will be helpful.