If i knew i would have submitted it very early . actually the way i arrived at the solution was on path of the authors’ approach itself and , so writing out some numbers for the smaller values of n <= 7 , i saw this pattern 1 , 2 , 5 , 6 …And then stress tested it for all possible n (in the given constraints) and it luckily worked :)`
I can’t really understand the editorial. The second to last paragraph should be explained better, as it is the important part. So suppose we pick a number that makes the subarrays that were divisible, not divisible anymore, as explained in the editorial. How do I know there wasn’t a subarray that was not divisible before but it is now with the new number?
There is also a solution in which we can start with initial array as [7,22] then for n-2 times append last value of array + 7. I have verified by running a loop from 1 to 500 to check if the sum of previous values at a particular index i divided by it’s length does not give int value i.e. not divisible. But still the solution was NOT ACCEPTED.
Can anyone please tell me the reason behind it???
Here, is my code:
T = int(input())
for tc in range(T):
n = int(input())
arr = [7,22]
if n == 1:
print(3)
elif n==2:
print(arr)
else:
for i in range(n-2):
arr.append(arr[-1]+7)
for x in arr:
print(x,end=" ")
print()
My solution in Python 3
cook your dish here
for _ in range(int(input())):
n=int(input())
x=3
for i in range(1,n+1):
if(i%2==0):
print(x-2,end=’ ‘)
else:
print(x,end=’ ')
x=x+1
print()
this can be simply done by putting even numbers at odd index and odd numbers at even index
my soln
See my solution ,may be that will help you!
Why this solution is giving a wrong answer, can anybody tell me?
void test(){
int n;
cin>>n;
vector<ll>arr(n+1);
iota(all(arr),0);
for(int i=1;i<=n;i++)
{ // If I am doing arr[i]=arr[i-1] here, then it is giving ac.
while(true){
ll sum=arr[i];
bool flag=true;
for(int j=i-1;j>0;j--){
sum+=arr[j];
if(sum%(i-j+1)==0){
arr[i]++;
flag=false;
break;
}
}
if(flag){
cout<<arr[i]<<" ";
break;
}
}
}
cout<<endl;
}
JJ challenges his friend GG to construct an array A containing N distinct elements such that the following conditions hold:
“”“distinct”""
There is no need of doing any kind of pre-computation. If you dry run the solution for n = 2, 3, 4, 5 then you clearly see there is pattern formation.
You have to just initialize pt1 = 2 and pt2 = 3 and each time add +4 in both the pointer and print both the pointer one by one
ll n; cin >> n;
ll odd = 3;
ll even = 2;
for (ll i = 0; i < n; i++)
{
if (i % 2 == 0) {cout << even << " "; even += 4;}
else {cout << odd << " "; odd += 4;}
}
cout << ed;
Hey, ig in case-1 you are calculating the (n/2)th term of the AP rather than the sum
oh, i didn’t noticed that, thank you
why this works??
even+odd =odd and not divisible by 2.
for length=3, sum will be (x+x-1+x+2)=3x+1… so we can conclude that for length of n we get sum as nx+y, y is remainder and y!=n so it works. Correct me if something is wrong.
I didn’t get the proof. How can we ensure that n-1, n-2 length subarray doesn’t divide the sum and there always exists such number ? Can anyone elaborate a bit?
Thanks for noticing. I have updated the proof. 
What should be noticed in this…?
I didn’t get it.
Can you pls explain?
why cant we use 2,3,2,3,2,3,2… like this sequence?
suppose we select given subarray and assume it would consist p 2’s and q 3’s then sum (2p+3q)%(p+q) != 1 wouldnt this always be true for q >0 ?
I’m sorry if this is a rudimentary question.
In the text of the explanation, in line 16 ,
" In this N−1 possible numbers, there are also N−2
numbers which we can take such that subarray whose end points are 2 and N will not divisible by N−1 "
how did you know that there are N-2 numbers in {X + 1, …, X + N-1} where sum_A [2 ~ N] is not divisible by N-1?
all of them should be distinct, no worries i did the same mistake<<|| ||>>