OBTTRNGL - What is wrong with my solution.??

#include
using namespace std;
int main()
{
long long T,p;
long long k,A,B;
long long i;
float theta;
cin>>T;

for(i=1;i<=T;i++)
{
	cin>>k>>A>>B;
	
	
	if(B-A>0)
	p=B-A;
	else
	p=k-B+A;
	
	if(A!=B&&A<=k&&B<=k&&k>=1)
	{
	
	theta=p*360/k;
	if(theta<180)
    cout<<(p-1)<<endl;
	else if(theta>=180)
	cout<<"0\n";
	}
	else
	cout<<"0\n";
}
return 0;

}

Part I

"p = k - B + A;"

is a wrong statement. Instead it should be

p = A - B;

Why?

Because, if the input is

7 5 6

means k = 7, A = 5, B = 6

and B + A exceeds k, therefore p goes negative and you might end up WA

Part II

else if(theta>=180)
printf("0\n");

is also incorrect

Instead it should be:

else if (theta == 180)
printf("0\n");
else
printf("%d\n", (k - p) + 1);

NOTE: You can also solve this question by a completely different approach, as mentioned by @sandeep_007

Hey @robof1,

I think your approach to solve the problem is wrong, instead of this you can solve the problem by taking a circle and finding how many points lie exactly in between them. if the two given points are on diametrically opposite points then using mathematics it can be proved that for all the points in between it will form a right angled triangle. otherwise for all other cases the number of minimum number of points lie in between them from clockwise and anticlockwise direction is our solution.

if(A > B) swap(A,B);

ll d = min(abs(A-B),abs(k-B+A));

if(k%2 == 0 and d == k/2){

cout << 0 << ā€œ\nā€;

}

else{

cout << d-1 << ā€œ\nā€;
}

Hope this helps!

you can also see my code.