Whats wrong in this solution?

The status of this solution is “Partially correct”.
#include
using namespace std;

int main(){
int t;
cin>>t;
while(t–){
long long n,a,b,k;
long long coun=0;
cin>>n;
cin>>a;
cin>>b;
cin>>k;

    for(long long i=1;i<=n;i++){
        if((i%a==0 && i%b!=0) || (i%a!=0 && i%b==0)){
            coun++;
        }
    }
    if(coun>=k) {
        cout<<"Win"<<endl;;
    }
    else {
        cout<<"Lose"<<endl;
    }
}
return 0;

}

Could you please provide a link to the question as well? How do you expect others to correct your code without knowing the question.

@akash19jain is absolutely right. @shyam339 please provide a link to the problem and your code in the future. This will help others in assisting you.

The code of the problem is HMAPPY2 and here is a link to it.

Subtask 2: (TLE)

Notice that for this subtask, K and N can be as high as 10^{18}. So if you run a loop from 1 to N, and thus - from 1 to 10^{18}, you will get TLE. Instead, you need to find a way such that it counts, without any loops, all numbers from 1 to N,

  1. Which are divisible by A (x)
  2. Divisible by B (y)
  3. Divisible by both A and B (z)

Then the count will be x+y-2z;

  • x is nothing but N/A
  • y is nothing but N/B
  • Now we need to find out z, which is, number of numbers from 1 to N divisible by both A and B. To find z, we need to find the LCM of A and B. We can find the LCM if we find out the GCD of A and B (Remember LCM = (A*B)/GCD). You can read about finding the GCD here. Once we have the LCM, then z = N/LCM.

Here is my AC code for this problem. Feel free to ask if you have any more doubts.