Wrong answer on Love is in the Air(CC005)

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.

What approach did you use ? ,I did it using sieve
https://www.codechef.com/viewsolution/29942386

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: CodeChef: Practical coding for everyone

1 Like

Made such a silly mistake, totally missed that part. Thank you @gankutsuou

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.