MSV oct long code

In this approach i am updating the frequency of factors of each number ,
as we can get to know the divisibility count through the count of occurence of a factor

Thus at each step we check the count and the one with maximum count will be our answer

#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin>>t;
while(t–){
long long n;
cin>>n;
long long col[n];
for(int i=0;i<n;i++){
cin>>col[i];
}
int freq[1000001]={0},ma=-1;
for(int i=0;i<n;i++){
if(freq[col[i]]>ma){
ma=freq[col[i]];
}
for(int j=1;j<=sqrt(col[i]);j++){
if(col[i]%j==0){
freq[j]++;
if((col[i]/j) !=j)
freq[col[i]/j]++;
}

        }
    }

    cout<<ma<<endl;
}

}

5 Likes

Wow!! Back to back such awesome editorials!!!
Feels like heaven!! :innocent:

8 Likes

Feels like hackerearth :rofl::rofl:

7 Likes

May you explain your solution.

Added a brief idea check out

What’s the complexity of this solution? Isn’t it greater than O(n*sqrt(n))?