Greatest Common Divisor - Programming Question

44 Views Asked by At

You are given a number $g$. Find a sequence $A$ of length $n$ which satisfies the following condition:

  1. $GCD ( A_0, A_1, A_2, .... ,A_i, ..... ,A_{n-1} ) = g.$
  2. $A_i > g, \ 0 \le i < n.$
  3. $A_i \ge A_j,\ \forall j \le i$
  4. 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;