mohittkkumar's blog

By mohittkkumar, 4 years ago, In English

So, I was solving this problem ------ https://codeforces.com/contest/1285/problem/F

It wants us to find out maximum LCM value pair in an array. I saw this problem elsewhere ( then came to know it was copied from here) and was thinking how to solve it.I couldn't come up with a ideal approach, so i tried many greedy methods and none of them seemed to work. Until I came up with this approach

What i did was —

For every i in 1 to MAX_NUMBER :

Find all multiples of i store it in a vector (say vec).

    Find the maximum element in the original input array that is not present in vec (say M)

    Find the LCM of M with all elements in vec and keep track of max LCM so far.

Finally Output the max LCM so far.

Solution link -- https://codeforces.com/contest/1285/submission/78453487

Now when initially i wrote it and submitted it on the platform i got 7 Wrong verdict : 6 were due to signed integer overflow and 1 was because all the elements in the array were same so i was not getting another no outside the 'vec'. So, its not like I kept improving this method after learning from test cases. This method somehow was correct for the testcases.

Now there can be two things :

  1. This method is not correct and fails on many cases that weren't in the test. However I couldn't find such testcase on my own. I would be glad if someone finds it out.
  1. This method actually is correct. In that case also, can someone tell me why it is correct, I cant prove it.

I am eagerly waiting for some answers as it is bugging me for quite some time now.

This is my first entry on codeforces, so forgive me if i missed out some necessary etiquettes.

EDIT : I gave the wrong problem link. So i have edited it.

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it