You are given a number $g$. Find a sequence $A$ of length $n$ which satisfies the following condition:
- $GCD ( A_0, A_1, A_2, .... ,A_i, ..... ,A_{n-1} ) = g.$
- $A_i > g, \ 0 \le i < n.$
- $A_i \ge A_j,\ \forall j \le i$
- Define a function, $sum(A) = A_0 + A_1 + .... + A_{n-1}.$
If multiple sequences satisfy the first three properties, print the one which minimizes $sum(A)$ function.
This is the program I wrote:
int g=0, n=0;
cin>>g>>n;
n += 2;
for(int j = 2; j< n; j++)
cout<< g*j<<" ";
It's incorrect, did I understood the question wrong. Or, can anybody explain to me the right logic?
Edit: I love math
The above program will become.,
int g=0, n=0;
cin>>g>>n;
cout<< g*(2n+1) << endl;