I am getting WA on this question of today’s contest.

Here’s my submission link- My solution

Can anyone provide a counter tc on which this fails.

the bug is in the sortByVal function.

it should be like this:

bool sortByVal(const pair<ll, ll> &a, const pair<ll, ll> &b) {

if(a.second == b.second)return (a.first < b.first);

return a.second < b.second;

}

if the pairs have same frequency the function must put the one with minimum value first

else put the one with minimum frequency first.

submission: https://www.codechef.com/viewsolution/29944310

1 Like

I simply factorise the given number by dividing it with the divisor of a number and keep updating the maximum prime factor and storing it in a vector.