MAGICMOD - Editorial

Not that easy bro. Your case will get halted very quickly. Say we try to check for given x, since a[0] = a[1] in your test case, it will halt in 1 step instead of going till n length.

It’s VERY VERY tricky to generate a case which gives sum as huge factorizable number and EACH divisor goes till length of a given almost ~N distinct a[i]%divisor values (and repeat values like at end of array) , only then we can hit TLE.

But it’s not impossible either until author proves upperbound. It’s not fair to put such ambiguous question in contest.

2 Likes

:man_facepalming: Yeah you’re right

@cherry0697 Kindly address elephant in room and comment on proven upperbound on Time complexity on mine/other’s comment!!!

1 Like

OH MY GOD!! I DIDN"T implement this exact solution because i thought it would give a TLE!!!
i was looking for O of n or nlog(n)

I think you should not perform any operations if any number is present more than once because than a solution is not possible and print NO.

Some solutions passed this test, some - not, nice tests :slight_smile:
n = 3
arr: 2 2 2

2 Likes

4*108 operations cannot be completed in 1 second time limit,
because, in 1 second, only 108 operations can be completed, so why the approach mentioned in the editorial is not a TLE?
@cherry0697 @aryanc403

Number of factors of 963761198400 is 2809 because we are excluding factors less than equal to 1e5 and greater than equal to 1e7.

Proof - Click Here

But, Number of operations is still 2.8*108 , which cannot be completed in 1 second, then how @cherry0697 and @aryanc403 are claiming, that these operations are enough to get completed in 1 second?

@cherry0697, Can you tell what was the intuition to sum up the whole array elements and remove the sum of the permutation?

Till this point in the editorial, I was able to understand, but when the summing part came, I was clueless, how to build an intuition like this?

I mean to say, what is the intuition of approaching a problem like this, because it seems somehow un-natural for me to sum up the elements and make equations.

Can you share some light on this?

Can we say that X should be greater than n, and therefore factors of Q’ should be greater than n ?

1 Like

N < x <= y
where y is the minimum num which is part of array but not the part of permutation ?

https://www.codechef.com/viewsolution/59380718
can anyone help me what i am doing wrong here ?

Hey for the n*(n+1) ~ 10^10 and so int would give overflow. Same with the sum variable for the sum of array.

It goes like this that suppose its possible to form permutation from some X, then
for each A[i]

Ai = Qi*X + Ri : Here Ai is element of array, X is chosen divisor and Ri is remainder left. As we said that we supposed that answer is possible then Ri is actually all numbers form 1 to N. So if we sum up each Ai then

sum(A) = sum(R) + (Q1+Q2+Q3+…Qn)X
so : sum(A)-sum(R) = (Q1+Q2+…Qn)X. So we can say that X is basically a factor of sum(A)-sum(R). Moreover sum(R) = N(N+1)/2 as it is sum of 1 upto N so thus we can find all factors of sum(A)-sum(R) and check which one gives the correct answer But still this approach should give TLE as suppose all A[i] are of order 10^7 and suppose I take N = 3 so sum(R) = 6 but sum(A) would be around 3
10^7 and now the number of factors of a number is given by multiplication of prime factorisation to some power i.e suppose Z = (a^p).(b^q).(c^r) here a,b,c are prime factors of Z, then number of factors of Z = (p+1)(q+1)(r+1). Now this thing could take up large values and thus the above approach provided in editorial must give TLE. I am sorry to say but each time I give a contest on codechef the level goes down each time. Some times even 10^7 wont work in 1s and sometimes even 10^8 will pass in 1s.

if(s==0) then why are we directlty printing yes and n+1, it’s not necessary for ex: 1 1 4 = (1+1+4 =6) also , 1 2 3 =(1+2+3 =6). Can someone make me clear??

2 Likes

Yeah I guess one check for existence for duplicates should have been there. It’s there in tester’s solution.

For the input
1
3
2 2 2
it returns
YES 4

which is wrong

My one of the subtask is not working can anyone tell me whats wrong with it?
Here is link to my code:code

We need to check because as in final equation: A N=R N +Q N ∗X

So (A N)-R N =Q N ∗X
Let K= (A N)-R N

So K=X*QN which means one of the factor of X will satisfy the equation so we have for all factors of X and check which will satisfy the equation

“Now we can also see that X needs to be the factor of this Q‘”
can anyone help me. how X need to be factor. I unable to get this.
@cherry0697