Plz post a solution not of O(n²)

The original family in the town has organised a homecoming party with N people invited Each person has a special trust value denoted by Array A . A person i will be friends with person j only if either A[i]%A[j]==0 or A[j]%A[i]==0. Find maximum no of friends each person can make and return the array

You can check it here

Two people so far asking the same question. Hope it’s not from an ongoing contest.

It is codenation question that held on 29th july so it is not from ongoing contest

Simple and easy to understand O(n\log{n}) code: hzVq0S - Online C++0x Compiler & Debugging Tool - Ideone.com