PlayStation india

All related to gaming in india

LightBlog

Breaking

Tuesday, 27 December 2022

A. Joey Takes Money codeforces solution in c++ || Codeforces Round #841 (Div. 2) and Divide by Zero 2022

 A. Joey Takes Money

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Joey is low on money. His friend Chandler wants to lend Joey some money, but can't give him directly, as Joey is too proud of himself to accept it. So, in order to trick him, Chandler asks Joey to play a game.

In this game, Chandler gives Joey an array a1,a2,,an (n2) of positive integers (ai1).

Joey can perform the following operation on the array any number of times:

  1. Take two indices i and j (1i<jn).
  2. Choose two integers x and y (x,y1) such that xy=aiaj.
  3. Replace ai by x and aj by y.

In the end, Joey will get the money equal to the sum of elements of the final array.

Find the maximum amount of money ans Joey can get but print 2022ans. Why multiplied by 2022? Because we are never gonna see it again!

It is guaranteed that the product of all the elements of the array a doesn't exceed 1012.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t4000). Description of the test cases follows.

The first line of each test case contains a single integer n (2n50) — the length of the array a.

The second line contains n integers a1,a2,,an (1ai106) — the array itself.

It's guaranteed that the product of all ai doesn't exceed 1012 (i. e. a1a2an1012).

Output

For each test case, print the maximum money Joey can get multiplied by 2022.



 code of this question ---

void solve()

{  

    int n;

    int res =0;

    cin >>n ;

    int arr[n];

    for ( int i =1 ; i<=n ; ++i )

    {

      cin >> arr[i];

    }

    int temp=0;

    for(int i=1; i<n ; ++i)

    {

      temp = arr[1]*arr[i+1];

      arr[1]=temp;

      arr[i+1]=1;

    }

    for(int i=1; i<=n; ++i)

    {

      res+=arr[i];  

    }

   ;

    cout<<res*2022<<nline;




}



No comments:

Post a Comment