# Getting wrong answer every time in (MULTHREE)

can anyone help me with this problem by generating a testcase for this problem, so that i can understand where i am going wrong.
i m not able to find what corner case i m missing every time while improvising the code bit by bit.

i have explained my logic in the beginning of my code
here is my solution ::

``````#include <iostream>
#define o ||
using namespace std;

/*

//  tailsum is a funtion to alculate the sum of tail numbers in the actual number

//  NOTE : by word block i mean "2486" or "4862" or "" or "8624" or "6248"

EXAMPLE 1 :  k =  13;  d1 =   8;   d2 = 1
the number formed will be :   8198624862486
in this the the first multiple of two (excluding 1st and 2nd digit ) is 8  (and not ounting 0 as multiple of 2 as in this case no formation of this pattern "2486")
(this first muliple of two if present, will be sotred in the variable "pointerval")

so block of "8624" repeats here twice leaving 8 and 6 as tail digits and there sum is given by function tailsum()

EXAMPLE 2 :  k =  21;  d1 =   4;   d2 = 0
the number formed will be :   404862486248624862486
in this the the first multiple of two (excluding 1st and 2nd digit ) is 4  (and not ounting 0 as multiple of 2 as ion this case no hcane for formatio of this pattern "4862")
(this first muliple of two if present, will be sotred in the variable "pointerval")

so block of "4862" repeats here for 4 times leaving 4,8 and 6 as tail digits and there sum is given by function tailsum()

HOW AM I CALCULATING SUM OF ALL DIGITS

ALSO since our main task is find if the actual number formed is divsible by 3
we need to find sum of all he digits, so i broke my sum variable into thre parts
1) sum of first two digits
2) sum of he blok being repeated n times (value of n is stored in variable 'R') and any of the 4 formations of the block has a sum of 20 so n (=R) times a blok means the sum of all the digits will be 20*n
3) sum of taildigits  (left in the end and couldn't fit in the block) is given by funtion tailsum()

on adding these three parts of sum we will get the required sum (of all digits)
and finally we check if this sum is divisible by 3 and thus printing either YES or NO

if there aren't any multipls of 2 present (like if 5 or 0 are present their code is present in else if statements)
if the value of k is less than or equal to 3 then a separat conditon is made.
*/

long long int tailsum (short int val, short int digit){
long long int sum;

if ( val ==2 && digit == 1 )
sum =2;

else if ( val ==2 && digit == 2 )
sum =6;

else if ( val ==2 && digit == 3 )
sum = 14;

else if ( val == 4 && digit == 3 )
sum = 18;

else if ( val ==4 && digit == 2 )
sum = 12;

else if ( val ==4 && digit == 1 )
sum = 4;

else if ( val ==8 && digit == 3 )
sum = 16;

else if ( val ==8 && digit == 2 )
sum = 14;

else if ( val ==8 && digit == 1 )
sum = 8;

else if ( val ==6 && digit == 3 )
sum = 12;

else if ( val ==6 && digit == 2 )
sum = 8;

else if ( val ==6 && digit == 1 )
sum = 6;

return sum;
}

// driver function
int main()
{
short int T;
cin>>T;

for (int i =0; i<T; i++){
long long int k;
short int d1,d2;
short int pointer;
short int pointerval;
long long int R;
short int Q;
long long int sum = 0 ;
cin>>k>>d1>>d2;                // major inputs are done here

short int d3 = (d1 + d2)%10;
short int d4 = (d1 + d2 + d3)%10;

if (k<=3){
//code goes here
if (k == 2)
sum = sum + d1 + d2 ;

else {

sum = d1 + d2 + d3;
}

}

else {

if ( d3 == 2 o d3 == 4 o d3 == 8 o d3 == 6 ){
pointer = 3;
pointerval = d3;
sum = sum + (d1 + d2);

Q = (k - 2)%4;
R = (k - 2)/4;

sum = sum + ( (R*20) + tailsum (pointerval, Q) );

}

else if ( d4 == 2 o d4 == 4 o d4 == 8 o d4 == 6 ){
pointer = 4;
pointerval = d4;
sum = sum + (d1 + d3 + d2);

Q = (k - 3)%4;
R = (k- 3)/4;

sum =  sum + ( (R*20) + tailsum (pointerval, Q) );

}

else if (d3 == 0 ) {
sum = d1 + d2 ;
}

else if (d4 == 0 && d3 == 5) {
sum = d1 + d2 + 5;

}

}

if (sum % 3 == 0 )
cout<<"YES"<<endl;

else {
cout<<"NO"<<endl;
}
}        // all testases ends over here

return 0;
}``````