Generating Sequence

QUESTION

You are given a number g. Find a sequence A of length n which satisfies the following condition: \n\nGCD ( A0, A1, A2, …. ,Ai, ….. ,An-1 ) = g.\n\nAi > g, 0 i < n.\nAi > Aj, j < i\n\nDefine a function, *sum(A) = A0 + A1 + …. + An-1. \nIf multiple sequences satisfy first three properties, print the one which minimizes sum(A) function.*\n\n\n\nINPUT\n\nThe first line will contain T, the number of test cases. Next T lines follow. The ith line will contain two space separated integers, g and n, for the ith test case.\n\nOUTPUT\n\nFor each test case, print a line containing n space separated integers of sequence A.\n\nCONSTRAINTS\n\n1 <= T <= 1000 \n1 <= g <= 10^14\n2 <= n <= 1000.

ANSWER

#include <iostream>
using namespace std;
 
int main()
{
    int T; cin >> T;
    while(T--){
        long long g; int n;
        cin>>g>>n;
        long long g2=g*2;
      //  cout<<g2<<" ";
        while(--n) cout<<g2<<" ";
        cout<<g*3<<'\n';
    }
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO