C++ program to find perfect array of size n whose subarray is a good array


Suppose we have a number n. An array B is good if the sum of its elements is divisible by the length of this array. We can say an array A with n elements is perfect, if non-empty subarray of this array A is good and elements in A is in range 1 to 100. From the number n, we have to find an array A which is perfect.

So, if the input is like n = 4, then the output will be [7, 37, 79, 49], other answers are also possible.

Steps

To solve this, we will follow these steps −

for initialize i := 0, when i < n, update (increase i by 1), do:
   print 1

Example

Let us see the following implementation to get better understanding −

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

void solve(int n){
   for(int i=0;i<n;i++){
      cout<<"1"<<", ";
   }
}
int main(){
   int n = 4;
   solve(n);
}

Input

4

Output

1, 1, 1, 1,

Updated on: 03-Mar-2022

144 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements