Help me in solving TRIO problem

My issue

why should
Ai = Aj * (Ai - 3)
?

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here

}

Problem Link: Freedom Practice Coding Problem - CodeChef

It’s not that it should be that way. It is an option to solve this problem.

You are told three equations:
a = Ai - Aj
b = Ai + Aj
c = Ai * Aj

That also are related as an arithmetic progression. So:
b - a = c - b

How do you solve that?
You could try out a greedy brute force approach trying every possible pair with a complexity O(N*(N+1)/2).That approach is insanely slow.

Let’s try solving all those as an equation system. How are they related?

b - a = c - b
b + b - a = c
2 * (Ai + Aj) - (Ai - Aj) = Ai * Aj
2 * Ai + 2 * Aj - Ai + Aj = Ai * Aj
3 * Aj + Ai = Ai * Aj
3 + (Ai / Aj) = Ai
(Ai / Aj) = Ai - 3

Ai = Aj * (Ai - 3)
Ai / (Ai - 3) = Aj

Or any final form that works for you

Using a geometric, arithmetic, or any approach you feel more comfortable with, you can solve the function, and find the so-called numbers that works for the problem. So you avoid trying out every single pair of index.