#include

using namespace std;

int main() {

int n,i,d0,d1,mod;

long long num_dig;

cin>>n;

for(i=0;i<n;i++)

{

cin>>num_dig>>d0>>d1;

mod=(d0+d1);

if(mod%3==0)

cout<<“YES”<<"\n";

else

cout<<“NO”<<"\n";

}

return 0;

}

Pls suggest correct and efficient code,if possible!

Your code works well for some test cases. But for the test case 6 8 1. Your code will give YES, but actually its NO.

It will not always be correct to say that the sum of all digits will be divisible by three if the sum of first two digits is. Take the case with `4 3 6`

the number formed will be `3696`

whose sum of digits is `26`

, but the sum of first two digits is `9`

.

Try to find out the pattern. Take 2-3 examples, you will fing 8 6 2 4 repeats in some manner. It may be 6 2 4 8 as well.

Take 2-3 examples on your own and start writing the digits, you will be able to figure out the pattern.

Divisibility RULE: If sum of all digits(not just the first two) is divisible by 3 then only the number is divisible by 3!!