Help me in solving FIFTYPE problem

My issue

My code

# cook your dish here
x=int(input())
for i in range(0,x):
    count=0
    a=int(input())
    if(a%2!=0):
        c=a-3
        count+=1
        while(c>50):
            c-=3
            count+=1
        d=50-c
        r=d//2
        print(r+count)
    elif(a==50):
        print("0")
    else:
        if(a<50):
            p=50-a
            print(p//2)
        else:
            while(a>50):
                a-=3
                count+=1
            d=50-a
            r=d//2
            print(r+count)
            
        

Problem Link: FIFTYPE Problem - CodeChef

@pragathi40
The logic I used here was like this;

We need the level to be 50. Charging increases the level by +2, while using reduces the level by -3.

I took a while loop with the termination condition being battery level reaching 50%. There can be three different cases here;

  • Case 1: Battery at 50% already. No charge or usage required, zero as output.

  • Case 2: Battery lower than 50%, we keep charging until it’s equals to or more than 50%.

  • Case 3: Battery more than 50%, we keep using the device until it’s less than or equals to 50%

You can take a look at the following code for a better understanding.

#include <stdio.h>

int main(void) 
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int q=0;
        while(n!=50)
        {
            if(n>50)
            {
                n=n-3;
                q++;
            }
            else
            {
                n=n+2;
                q++;
            }
        }
        printf("%d\n",q);
    }
	
	return 0;
}