I need some help with the following question. The test cases given in the question are working just fine for my code, but still its giving ‘wrong answer’
long K=0;
int a=0;
int b=0;
K=sc.nextLong();
a=sc.nextInt();
b=sc.nextInt();
int num=a+b;
int sum=num+(num%10);
double res=0;
long total=0;
long pair=0;
if(K==2)
{
if(num%3==0)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
else{
int s= (num*2)%10 +(num*4)%10 +(num*8)%10 +(num*16)%10;
pair = (K-3)/4;
long rem =(K-3)%4;
if(rem==0)
{
sum+=0;
}
else
{
for(int i=1;i<=rem;i++)
{
res=((a+b)*Math.pow(2, i))%10;
sum+=res;
}
total=sum+(pair*s);
if(total%3==0)
{
System.out.print("YES");
}
else {
System.out.print("NO");
}
}
}