WA on original constrait - Appy and Contest

Hey guys,
so i passed the inititial constraint test,but it doesnt pass the original constraint. I’ve looked at other people’s successful codes and they are conceptually same.Can anyone point out whats the mistake in my solution.
Thanks in advance :slight_smile:
Here’s my code:

#include <bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin >> t;
        ll n,a,b,k;
        cin >> n >> a >> b >> k;
        ll cnt =0;
        cnt += n/a;
        cnt += n/b;
        cnt -= 2*n*__gcd(a,b)/(a*b);
            cout << "Win" << endl;
            cout << "Lose" <<endl;

Link to the problem?

1 Like

2*n*gcd(a,b)/(a*b) would be not be same as 2*(n/ ((a*b)/gcd(a,b))) since the division is floored division. So, first compute the lcm separately and do 2*(n/lcm).
Also, 2*n/lcm would not be same as 2*(n/lcm).


Thanks a lot,it passed all the test now :slight_smile:

1 Like