Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Alternate Additions CodeChef Solution

Problem – Alternate Additions CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.
<<Previous CodeChef Problem Next Codechef Problem>>

Alternate Additions CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
	    int a,b;
	    cin>>a>>b;int c=0;
	    if((b-a)%3==2){
	        cout<<"NO"<<endl;
	    }
	    else{
	        cout<<"YES"<<endl;
	    }
	    
	}
	return 0;
}

Alternate Additions CodeChef Solution in C++14

#include <stdio.h>
#define xy long long int
int result();
int yes();
int no();


int main(void) {
	// your code goes here
	int tst; scanf("%d",&tst);
	while(tst--)
	    result();
	return 0;
}

int result()
 {
        long long int a,b;
	    scanf("%lld %lld",&a,&b);
	    int i=b-a;
	    int j=3;
	    int k=2;
	    int l=i%j;
	    if(l==k)
	        yes();
	   else
	        no();
	       
     return 0;
 }
 int yes()
 {
     printf("No\n");
     return 0;
 }
 int no()
 {
     printf("Yes\n");
     return 0;
 }

Alternate Additions CodeChef Solution in PYTH 3

# cook your dish here
T=int(input())
for x in range(T):
    l,m=map(int,input().split())
    s=m-l
    if s==1:
        print("Yes")
    elif s==2:
        print("No")
    elif s%3==0:
        print("Yes")
    elif s%3==1:
        print("Yes")
    else:
        print("No")

Alternate Additions CodeChef Solution in C

#include <stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        if((b-a)%3==2)
        printf("No\n");
        else
        printf("Yes\n");
    }
    return 0;
}

Alternate Additions CodeChef Solution in JAVA

/* 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 Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[2*n];
		int odd=0,even=0;
		for(int i=0;i<2*n;i++)
		{
		    arr[i]=sc.nextInt();
		}
		for(int i=0;i<2*n;i+=2)
		{
		    if((arr[i+1]-arr[i])%3==0)
		    {
		        System.out.println("YES");
		    }
		    else if((arr[i+1]-arr[i])%3!=0 &&(arr[i+1]-arr[i])%3==1)
		    {
		        System.out.println("YES");
		    }
		    else 
		    {
		        System.out.println("NO");
		    }
		    
	}
}
}

Alternate Additions CodeChef Solution in PYPY 3


t=int(input())
while(t>0):
    t-=1
    a,b=map(int,input().split())
    if((b-a)%3==0 or (b-a)%3==1):
        print('YES')
    else:
        print('NO')
    

Alternate Additions CodeChef Solution in PYTH

t = int(raw_input())
for i in range(t):
	st = raw_input().split()
	A = int(st[0])
	B = int(st[1])
	if (B-A)%3 == 2:
		print 'NO'
	else:
		print 'YES'
	# endif
# endfor i

Alternate Additions CodeChef Solution in C#

using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
		int T = Convert.ToInt32(Console.ReadLine());
		while(T>0)
		{
		    string[] s = Console.ReadLine().Split(' ');
		    int A = Convert.ToInt32(s[0]);
		    int B = Convert.ToInt32(s[1]);
		    if((B-A)%3==2)
		    {
		        Console.WriteLine("NO");
		    }
		    else
		    {
		        Console.WriteLine("YES");
		    }
		    
		    T--;
		}
	}
}

Alternate Additions CodeChef Solution in NODEJS

process.stdin.resume();
process.stdin.setEncoding('utf8');

// your code goes here
let input = ''
process.stdin.on('data', function(chunk){
    input += chunk 
});
process.stdin.on('end', function(){
   input = input.split('\n')
   for (i = 1; i <= input[0]; i++) {
      line = input[i].split(" ");
      A = parseInt(line[0])
      B = parseInt(line[1])
      D = (B - A) % 3;
      if (D === 2) console.log("NO"); else console.log("YES");
   }
});

Alternate Additions CodeChef Solution in GO

package main
import (
    "fmt"
    "bufio"
    "os"
)


func Reader(c chan int) {
    scanner := bufio.NewScanner(os.Stdin)

    for scanner.Scan() {
        line := scanner.Text()
        number := 0
        beg := false
        for i := 0; i < len(line); i++ {
            if '0' <= line[i] && line[i] <= '9' {
                beg = true
                number = number * 10 + int(line[i] - '0')
            } else {
                if beg == true {
                    c <- number
                }
                number = 0
                beg = false
            }
        }
        if beg == true {
            c <- number
        }
    }
}


func main(){
    w := bufio.NewWriter(os.Stdout)    
    defer w.Flush()

    inp := make(chan int, 4096)
	go Reader(inp)
	
	t := <-inp
	for i := 0; i < t; i++ {
        a, b := <-inp, <-inp

        delta := b - a
        if delta % 3 == 0 || (delta + 2) % 3 == 0 {
            fmt.Fprintln(w, "Yes")
        } else {
            fmt.Fprintln(w, "No")
        }
	}
}

Alternate Additions CodeChef Solution Review:

In our experience, we suggest you solve this Alternate Additions CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *