c++ – Rearrange an array so that arr[i] becomes arr[arr[i]] with O(1) extra space

I was writing a code for the following problem :
https://practice.geeksforgeeks.org/problems/rearrange-an-array-with-o1-extra-space3142/1/?category()=Arrays
My Code :

#include<bits/stdc++.h>
using namespace std;
class Solution{
public:

void arrange(long long arr(), int n) {
    long long i1,i,temp,temp1;
    for( i = 0 ; i < n ; i++ )
    {
        i1 = i;
        temp = arr(i);
        if( arr(i1) < n )
        {
            while( arr(i1) < n )
            {
                if(arr(arr(i1)) >= n)
                {
                    arr(i1) = temp + n;
                    break;
                }
                temp1 = arr(i1);
                arr(i1) = arr(arr(i1)) + n;
                i1 = temp1;
            }
        }
    }
    for( i = 0 ; i < n ; i++ )
    {
        arr(i) -= n;
    }
}

};

int main(){

int t;
//testcases
cin>>t;
while(t--){

    int n;
    //size of array
    cin>>n;
    long long A(n);

    //adding elements to the array
    for(int i=0;i<n;i++){
        cin>>A(i);
    }
    Solution ob;
    //calling arrange() function
    ob.arrange(A, n);

    //printing the elements
    for(int i=0;i<n;i++){
        cout << A(i)<<" ";
    }
    cout<<endl;
}
return 0;

}

This code works well for all my inputs upto even 1000. I’ve tried various permutation for 1000 and 100 but it still it works fine. But the code is not working properly for a test case permutation of 104573. I’ve even taken long long so I feel the largeness of the value should not effect it.