# Multiple three

ok so I went through that github link. I think it’s old. In test input three the last input is wrong. ( 2 9 5 )

Also my code passed all the other test cases but is still getting WA.

so my approach is this
I found a pattern in the number…
there is a repeating pattern of 8 6 2 4 from k=3

so I made a variable sum as (d0= 1st no and d1= 2nd no)
s= k/4
m=k%4
sum = (sum of digits of 3rd number) + s*(8+6+4+2)
now I add the remaining digits. For ex if last digit of k=4 is 8 then the next in line is 6 and then 2 and then 4
I think I ve covered everything, but still getting WA.

The code is:

``````import java.util.*;
import java.io.*;
import java.math.*;

class Rextester
{
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;

{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
}

{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
}

{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}

public int nextInt() throws IOException
{
int ret = 0;
while (c <= ' ')
boolean neg = (c == '-');
if (neg)
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');

if (neg)
return -ret;
return ret;
}

public long nextLong() throws IOException
{
long ret = 0;
while (c <= ' ')
boolean neg = (c == '-');
if (neg)
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}

public double nextDouble() throws IOException
{
double ret = 0, div = 1;
while (c <= ' ')
boolean neg = (c == '-');
if (neg)

do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');

if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}

if (neg)
return -ret;
return ret;
}

private void fillBuffer() throws IOException
{
buffer[0] = -1;
}

{
fillBuffer();
return buffer[bufferPointer++];
}

public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}

public static void main(String[] args) throws IOException
{
int test=in.nextInt();
while(test-- >0){
int k=in.nextInt();
int d0=in.nextInt(), d1=in.nextInt();
String D2=d0+""+d1+""+((d0+d1)%10);
//System.out.println(D2);
int d2=Integer.parseInt(D2);
String D3=d2+""+((d0+d1+d2)%10);
//System.out.println(D3);
int d3=Integer.parseInt(D3);
//check for k<=3
if(k==2){
if((d0+d1)%3==0)
System.out.println("YES");
else
System.out.println("NO");
}
else if (k==3) {
if((d2)%3==0)
System.out.println("YES");
else
System.out.println("NO");
}
else if (k==4) {
if((d3)%3==0)
System.out.println("YES");
else
System.out.println("NO");
}
else if (d3%10==0) {
if(d2%3==0)
System.out.println("YES");
else {
System.out.println("NO");
}
}
else{
int skip=8+6+2+4;
int skp[]={8, 6, 2, 4};
long summ=d0+d1+d2%10;
BigInteger sum= new BigInteger(String.valueOf(summ));
//System.out.println(sum);
k=k-4;int index=-1;
if(d3%10==8)
index=0;
if(d3%10==6)
index=1;
if(d3%10==2)
index=2;
if(d3%10==4)
index=3;
//long s= k/4;
// BigInteger s= new BigInteger((k/4).toString());
int m= k%4;
//sum= sum+s*skip;
//System.out.println(index);
for(int i=0;i<=m;i++){
int temp=skp[(index)%(skp.length)];
//System.out.println("--> "+sum);
index++;
}
//System.out.println("sum: "+sum);
if(sum.mod(BigInteger.valueOf(3)).intValue() == 0)
System.out.println("YES");
else {
System.out.println("NO");
}
System.out.println("SUM:   "+sum);

}
}
}
}
//https://github.com/strikersps/Competitive-Programming/tree/master/Code-Chef/Multiples-of-3/test-cases
``````

I believe the code is correct. If anyone can please help me to find the test case for which it is failing, it would be a huge help.