I understand that checkmodulo() is being used to count the number of factors of each element , and then we are returning the max number of factors any element in the array , but I dont see how this works ? Can someone explain
Q1. Solution.
#include <bits/stdc++.h>
using namespace std;
void checkmodulo(int x,map<int,int> &mpp){
int i=2;
while(i<=x){
if(x%i==0){
mpp[i]++;
}
i++;
}
}
int main()
{
int arr[]={3,6,9,12,15};
int n=5;
map<int,int>mpp;
for(int i=0;i<n;i++){
checkmodulo(arr[i],mpp);
}
int maxi =0;
for(auto it:mpp){
if(it.second>maxi){
maxi = it.second;
}
}
cout<< n-maxi;
}
In which college these questions were asked?