Total number of pairs that can be formed
int total = ( n * ( n - 1 ) ) / 2 ; int ans = total - pref [ n ] ; System . out . print ( " Number ▁ of ▁ pairs ▁ from ▁ 1 ▁ to ▁ " + n + " ▁ are ▁ " + ans + "NEW_LINE"); }