PROBLEM LINK:
Author: Abhay Tiwari
DIFFICULTY:
EASY.
PREREQUISITES:
Mathematics
EXPLANATION:
To count the number of triangles formed by N lines on a plane(no three lines are concurrent and non of them are parallel), we can do this by calculating n \choose 3 as any combination of three lines will form a triangle, so we have to choose any three lines out of N lines and this can be done in n \choose 3 ways.
Similarly for the total number of intersections we can calculate n \choose 2, as any combination of two lines will intersect each other. Take care of integer overflow for large numbers, use long long.
SOLUTIONS:
Setter's Solution
#include<iostream>
#define sc(a) scanf("%lld",&a)
#define ll long long
#define M 1000000007
using namespace std;
int main() {
ll t ;
cin>>t;
while(t--)
{
ll n;
cin>>n;
cout<<(n*(n-1)*(n-2))/6<<" "<<(n*(n-1))/2<<endl;
}
}