how would you write a checker for problem B from the contest Think-cell round 1 with complexity less than n^2 ?
in others words given a permutation of size n determine weather there exists 2 indices i and j (1 <= i,j <n) i != j , where p(i) devides p(j) and p(i+1) devides p(j+1)
Auto comment: topic has been updated by Axial-Tilted (previous revision, new revision, compare).
Iterate over all $$$1\le i\le n$$$ — all values $$$1, 2,\dots, n$$$ appear exactly once as $$$p_i$$$. For each value of $$$p_i$$$, there are $$$\left\lfloor n/p_i\right\rfloor$$$ distinct values of $$$p_j$$$ such that $$$p_i$$$ divides $$$p_j$$$. You can check all of these to make sure none of them satisfy the condition. In total, there are $$$O(n \log n)$$$ pairs $$$(i, j)$$$ we need to check (harmonic series)
thats what i was looking for , thanks
It will require O(n) space as well?
Good algorithm,I like it.
just like 1/1+1/2+1/3+1/4+...+1/n that's quick enough
just write a 2-level permutation i.e. 4 1 3 2 it is the same problem as K-Lever Permutation you can verify it by yourself by writing some permutations and trying to prove it. Keep in mind if n is odd then the second value will be 2 and if n is even then second value will be 1. then simply write n, sec, n — 1, sec + 1 ... and so on n-times
Bro, the blog asks for ways to efficiently write a checker for problem B, not the solution for problem B
Oh my contributions ... :( I misunderstood it. Ahhhh!!!