MULTHREE - Editorial

@kasa your formula is correct may be because of some overflow you are getting wrong answer

@divik544 he is correct can u explain y is he adding 3rd digit and possibly last digit?

The example given for k=12.
But won’t x=d11 only? di goes from 2<=i<k, right. Please change that.

@aman935 yes it should be d11 only

Got it…

The answer is “YES”. What “correct solutions” are you talking about?

consider this one CodeChef: Practical coding for everyone.
I have compiled it here Online Compiler and IDE - GeeksforGeeks

i came with the same formula but i didnt get the right result as well can anyone explain please?

there is no dot at the end of the link. Correct link : CodeChef: Practical coding for everyone

Well, then we have another problem with weak test cases.

The second term gives you \sum d_i \mod 10 \mod 3, and you need \sum d_i \mod 3.

yes. thanks for confirming.

Try

4 2 5

Hi Akshay,

Thanks for your response. However I see that the number generated by 4 2 5 is 2574. Which is divisible by 3 as per my output, and it is also divisible by 3. Please let me know if I’m wrong somewhere.

Regards,

Ruddra

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.;
import java.io.
;

class Rextester
{
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;

public Reader()
{
  din = new DataInputStream(System.in);
  buffer = new byte[BUFFER_SIZE];
  bufferPointer = bytesRead = 0;
}

public Reader(String file_name) throws IOException
{
  din = new DataInputStream(new FileInputStream(file_name));
  buffer = new byte[BUFFER_SIZE];
  bufferPointer = bytesRead = 0;
}

public String readLine() throws IOException
{
  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;
  byte c = read();
  while (c <= ' ')
  c = read();
  boolean neg = (c == '-');
  if (neg)
  c = read();
  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;
  byte c = read();
  while (c <= ' ')
  c = read();
  boolean neg = (c == '-');
  if (neg)
  c = read();
  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;
  byte c = read();
  while (c <= ' ')
  c = read();
  boolean neg = (c == '-');
  if (neg)
  c = read();

  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
{
  bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
  if (bytesRead == -1)
  buffer[0] = -1;
}

private byte read() throws IOException
{
  if (bufferPointer == bytesRead)
  fillBuffer();
  return buffer[bufferPointer++];
}

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

}

public static void main(String[] args) throws IOException
{
Reader in=new Reader();
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 sum=d0+d1+d2%10;
//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;
int s= k/4;
int m= k%4;
sum= sum+s*skip;
//System.out.println(index);
for(int i=0;i<=m;i++){
sum+=skp[(index)%(skp.length)];
//System.out.println("–> "+sum);
index++;
}
//System.out.println("sum: "+sum);
if(sum%3==0)
System.out.println(“YES”);
else {
System.out.println(“NO”);
}
}
}
}
}

I have no idea why am I getting WA in this. Please help

Can someone help me find a bug in my code. For sample inputs it shows right output and for the other I have tested few using manual calculation. But when I submit it says WA.
codechef.com/viewsolution/31077750

Please help me in checking why it is not working

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class CodeChef2
{
public static void main (String[] args) throws java.lang.Exception
{
//your code goes here
Scanner sc=new Scanner(System.in);
/*int i=0;
System.out.println(" “+i);
i=Integer.MAX_VALUE;
System.out.println(” “+i);
long l=Long.MAX_VALUE;
System.out.println(” "+l);
*/

	int d0,d1,T;
	long k;
	
	T=sc.nextInt();
	
	for(int i=0;i<T;i++)
	{	
		k=sc.nextLong();
		d0=sc.nextInt();
		d1=sc.nextInt();
		int value=0;
		//System.out.print(k+ " "+ d0+ " "+ d1);
		int left;
		int s=d0 + d1;
	//	System.out.println("S:"+s);
		int N=(int)((k-3)/4);
		int cycle= ((2*s)%10) + ((4*s)%10) + ((8*s)%10 )+ ((6*s)%10);
	//	System.out.println("cycle:"+cycle);
		if(k==2)
			value=d0 + d1;
		else
		{
		    value= s + (s) + (cycle*N);
	//	System.out.println("value before left:"+value);
		left=(int)( k-3- 4*N);
	//	System.out.println("left:"+left);
		int p=2;
		for(int j=1;j<=left;j++)
		{  value+=((p*s)%10);
			p=(p*2)%10;
		}
		}	
	//	System.out.println("Value:"+value);
		if(value%3 == 0)
			System.out.println("YES");
		else
			System.out.println("NO");
	}

}

}

please help me to solve MULTHREE everything is oke but final answer is WRONG

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class CodeChef2
{
public static void main (String[] args) throws java.lang.Exception
{
//your code goes here
Scanner sc=new Scanner(System.in);
/*int i=0;
System.out.println(" “+i);
i=Integer.MAX_VALUE;
System.out.println(” “+i);
long l=Long.MAX_VALUE;
System.out.println(” "+l);
*/

	int d0,d1,T;
	long k;
	
	T=sc.nextInt();
	
	for(int i=0;i<T;i++)
	{	
		k=sc.nextLong();
		d0=sc.nextInt();
		d1=sc.nextInt();
		int value=0;
		//System.out.print(k+ " "+ d0+ " "+ d1);
		int left;
		int s=d0 + d1;
	//	System.out.println("S:"+s);
		int N=(int)((k-3)/4);
		int cycle= ((2*s)%10) + ((4*s)%10) + ((8*s)%10 )+ ((6*s)%10);
	//	System.out.println("cycle:"+cycle);
		if(k==2)
			value=d0 + d1;
		else
		{
		    value= s + (s) + (cycle*N);
	//	System.out.println("value before left:"+value);
		left=(int)( k-3- 4*N);
	//	System.out.println("left:"+left);
		int p=2;
		for(int j=1;j<=left;j++)
		{  value+=((p*s)%10);
			p=(p*2)%10;
		}
		}	
	//	System.out.println("Value:"+value);
		if(value%3 == 0)
			System.out.println("YES");
		else
			System.out.println("NO");
	}

}

}

please help me why answer is not coming right

https://www.codechef.com/viewsolution/31598444

Can someone tell me what I am doing wrong here?

https://www.codechef.com/viewsolution/33143536