I am trying to solve a problem that was in LunchTime this month. When I submitted my solution it worked for few test cases but didn’t worked(Gave me WA not TLE) for few.
Here is my code algorithm :
Collections.sort(myList);
for(int j = 0 ; j<N ; ++j){
for(int k = j+1 ; k < N ; ++k){
if(myList.get(j) == myList.get(k)) //When numbers are equal
pair++;
else if(myList.get(k)%myList.get(j) == 0){
long myWay = myList.get(k)/myList.get(j);
double myLog = Math.log(myWay)/Math.log(F);
if(myLog%1==0)
pair++;
}
}
}
I know my algorithm’s time complexity is more and I have read the editorial for better algorithm BUT still I want to know why my code gave me Wrong answer for few test cases.
Thank you in Advance.