Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Alternating Work Days CodeChef Solution

Problem -Alternating Work Days 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.

Alternating Work Days CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,p,q;
        cin>>a>>b>>p>>q;
        if((p%a ==0)&&(q%b==0)){
            long long x=p/a,y=q/b;
            if((x-y)==1||(y-x)==1||(x-y)==0||(y-x)==0)cout<<"YES\n";
            else cout<<"NO\n";
        }
         else cout<<"NO\n";
    }
	// your code goes here
	return 0;
}

Alternating Work Days CodeChef Solution in C++14

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second 
#define s second 
#define f0r(i,n) for(int i=0;i<n;i++)

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b)  (a/gcd(a,b))*b


int main(){ 
    
ios_base::sync_with_stdio(false);
cin.tie(NULL); 
cout.tie(NULL); 

int t;
cin>>t;
while(t--){  
 int a,b,p,q,a1,b1;
 cin>>a>>b>>p>>q;
 a1=p/a;
 b1=q/b;
 if((abs(a1-b1)==1 ||abs(a1-b1)==0)&& a1*a==p && b1*b==q )cout<<"YES";
 else cout<<"NO";
 cout<<"\n";

 
}  
}
        

        
 

Alternating Work Days CodeChef Solution in PYTH 3

t=int(input())
for i in range(t):
    a,b,p,q=map(int,input().split())
    if p%a==0 and q%b==0:
        s=p//a 
        t=q//b
        if abs(s-t)>1:
            print("NO")
        else:
            print("YES")
    else:
        print('NO')

Alternating Work Days CodeChef Solution in C

#include <stdio.h>

int main(void)
{
    int t,i;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        int A,B,P,Q;
        scanf("%d%d%d%d",&A,&B,&P,&Q);
        if(P%A!=0||Q%B)
        {
            printf("NO\n");
        }
        else if(abs((P/A)-(Q/B))<=1)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }

	return 0;
}

Alternating Work Days 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
	{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out));
		int tt=Integer.parseInt(reader.readLine().trim());
		while(tt-->0){
		    long[] nums=parseLong(reader.readLine());
		    long a=nums[0], b=nums[1], p=nums[2], q=nums[3];
		    boolean isDoable=false;
		    //alice works on odd days
		    if(p%a==0){
		        long od=p/a;
		        if(b*od==q || (od-1L)*b==q){
		            isDoable=true;
		        }
		    }
		    if(q%b==0){
		        long od=q/b;
		        if(od*a==p || (od-1L)*a==p){
		            isDoable=true;
		        }
		    }
		    writer.write((isDoable?"YES\n":"NO\n"));
		}
		writer.flush();
	}
	
    
    private static int[] parseInt(String str) {
        String[] parts=str.split("\\s+");
        int[] ans=new int[parts.length];
        for(int i=0;i<ans.length;i++){
            ans[i]=Integer.parseInt(parts[i]);
        }
        return ans;
    }

    private static long[] parseLong(String str) {
        String[] parts=str.split("\\s+");
        long[] ans=new long[parts.length];
        for(int i=0;i<ans.length;i++){
            ans[i]=Long.parseLong(parts[i]);
        }
        return ans;
    }
}

Alternating Work Days CodeChef Solution in PYPY 3

t=int(input())
for i in range(0,t):
  a,b,p,q=map(int,input().split())
  if(p%a==0 and q%b==0):
    if(abs((p//a)-(q//b))==0 or abs((p//a)-(q//b))==1):
        print('YES')
    else:
        print('NO')
  else:
      print('NO')

Alternating Work Days 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])
	P = int(st[2])
	Q = int(st[3])
	valid = False
	if (P%A == 0) and (Q%B == 0):
		if abs(P/A - Q/B) < 2:
			valid = True
		# endif
	# endif
	if valid:
		print 'YES'
	else:
		print 'NO'
	# endif
# endfor i

Alternating Work Days CodeChef Solution in C#

using System;
using System.Linq;
public class Test
{
	public static void Main()
	{
		
		int test = int.Parse(Console.ReadLine());
		while(test-- >0){
		    int[] lines = Console.ReadLine().Split().Select(int.Parse).ToArray();
		    
		    int a =lines[0];
		    int b = lines[1];
		    int p = lines[2];
		    int q = lines[3];
		    
		    if((Math.Abs(((p/a)+1)-((q/b)+1))<=1) && p%a==0 && q%b==0){
                Console.WriteLine("YES");
            }
            else{
                Console.WriteLine("NO");
            }
		}
	}
}

Alternating Work Days CodeChef Solution in NODEJS

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

// your code goes here

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
    // console.log('a',inputString)
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n');
    // console.log('b',inputString)
    main();    
});

function readLine(){
    return inputString[currentLine++];
}

function main(){
    // input in nodeJs
	let test = parseInt(readLine(),10);
	while(test--){
		let [alice, bob, targetAlice, targetBob] = readLine().split(' ').map(Number);
        // output in nodeJs
		console.log(alterLogic(alice, bob, targetAlice, targetBob));
	}
}

function alterLogic(alice, bob, targetAlice, targetBob) {
    if (targetAlice%alice !== 0 || targetBob % bob !== 0) return 'No'
    
    const daysRequiredbyAlice = targetAlice/alice;
    const daysRequiredbyBob = targetBob/bob;
    
    if (daysRequiredbyAlice === daysRequiredbyBob) return 'Yes';
    // if (daysRequiredbyAlice + 1 === daysRequiredbyBob) return 'Yes';
    // if (daysRequiredbyAlice === daysRequiredbyBob + 1) return 'Yes';
    if (Math.abs(daysRequiredbyAlice - daysRequiredbyBob) === 1) return 'Yes';
    
    return 'No';
}

Alternating Work Days CodeChef Solution in GO

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}

func getInt() (a int) {
    scanf("%d\n", &a)
    return
}

func getIntLine() {
    str, _ := reader.ReadString('\n')
    str = strings.TrimSpace(str)
    
    for i, c := range strings.Split(str, " ") {
        arr[i], _ = strconv.Atoi(c)
    }
    return
}

const N int = 4
var arr [N]int


func main() {
	defer writer.Flush()
	
    t := getInt()
    for t != 0 {
        t--
        
        getIntLine()
        a, b, p, q := arr[0], arr[1], arr[2], arr[3]

        if p % a != 0 || q % b != 0  {
            printf("%s\n", "No")
        } else if p / a == q / b || p / a == q / b + 1 || p / a == q / b - 1 {
            printf("%s\n", "Yes")
        } else {
            printf("%s\n", "No")

        }
        
    }
}
Alternating Work Days CodeChef Solution Review:

In our experience, we suggest you solve this Alternating Work Days 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 Alternating Work Days CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Alternating Work Days 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 *