 # Long Challenge

Appy and Chef are participating in a contest. There are NN problems in this contest; each problem has a unique problem code between 11 and NN inclusive. Appy and Chef decided to split the problems to solve between them ― Appy should solve the problems whose problem codes are divisible by AA but not divisible by BB, and Chef should solve the problems whose problem codes are divisible by BB but not divisible by AA (they decided to not solve the problems whose codes are divisible by both AA and BB).

To win, it is necessary to solve at least KK problems. You have to tell Appy whether they are going to win or lose.

CODE:

#include<stdio.h>

int main(){
int i,n,a,b,k,c = 0;
printf(“Enter the numbers\n”);
scanf("%d %d %d %d",&n,&a,&b,&k);

``````for(i=1;i<=n;i++){

if(i%a == 0 || i%b == 0 && !(i%a == 0 && i%b == 0))
c++;
}
//printf("%d\n",c_a);
//printf("%d\n",c_b);
//printf("%d\n",c_ab);
//printf("%d\n",c_a+c_b-c_ab);

if(c >= k)
printf("\nWin");
else
printf("\nLose");
``````

}

I am a beginner. I got WA.Please help me

Could you please link the problem link in the question? Then it would be of great help in helping you where you went wrong!!

1 Like

In your code, precedence of Relational AND operator is higher than precedence of Relational OR operator, so you should change the if condition to the one in my code here. As a good practice, you should always use parenthesis where ever you are in doubt.
You should read this.

Also you need to read the Input/Output formats for the given problems. Usually in codechef, they give you T first, indicating that there will be T test cases, each of which will be having … . Something of this sort. And also, you should look at the constraints of the problems. In this case, I corrected your code so that you can see the errors. You should also see that, the corrected code will not pass all the subtasks, because the constraints of the problem say that N could have a value of 10^{18}, so obviously a O(N) algorithm is not going to work here. You need to think about an O(logN) or a O(1) algorithm.

2 Likes