HELP ON MULTHREE

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");
         }
         }
        
		}

If the snippet of code you mentioned is the same as you are currently using then I think you misplaced the brackets.

P.S. Try run your code for K = 3.

i have displayed the main part of my code. and there wasn’t any error during its execution. my code is running successfully for the three test cases given in the question but not for the hidden cases i guess.
and no its for working for K=3

If rem == 0 then your code will not print anything.