We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
n=int(input().strip())p=list(map(int,input().strip().split(' ')))foriinrange(n):print(p.index(p.index(i+1)+1)+1)''' Our task is :: For each x from 1 to n , print an integer denoting any valid y satisfying the equation p(p(y)) = x on a new line.Here p(y) means, the value at y index in list p. But the range of y goes from 1 to n, and range of python list goes from 0 to n-1. so make it balanced, we need to add 1 in each time in y to make it equal to python index.for example32 3 1Now, x goes from 1 to 3 (inclusive), but since the range goes from 0 to n-1, 1 needed to add here to balance it.when i = 0, x = i+1, you need to find that at which index 1 is coming in list pfirst_index = p.index(i+1)now, u need to find at which index the first_index is coming, but since , the index coming as output in above line is from 0 to n-1, 1 needed to add to balace itsecond_index = p.index(first_index+1)since this will also be 0 to n-1,, add 1ans = second_index + 1I have written a new code so u can understand how each line works'''n=int(input().strip())p=list(map(int,input().strip().split(' ')))foriinrange(n):x=i+1first_index=p.index(x)second_index=p.index(first_index+1)ans=second_index+1print(ans)
Sequence Equation
You are viewing a single comment's thread. Return to all comments →