Header Ad

Codechef Test Score problem solution

In this Codechef Test Score problem solution In a test, there are NN problems, each carrying XX marks.

In each problem, Chef either received XX marks or 00 marks.

Determine whether is it possible for Chef to achieve exactly YY marks.

Codechef Test Score problem solution


Problem solution in Python.

for i in range (int(input())):
    n,x,y=map(int,input().split())
    if ((n*x)-y)%x==0:
        print("yes")
    else:
        print("no")


Problem 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 T = sc.nextInt();
		for(int i = 0;i< T; i++){
		    int N = sc.nextInt();
		    int X = sc.nextInt();
		    int Y = sc.nextInt();
		    
		        if( Y % X == 0){
		            System.out.println("yes");
		        }else{
		            System.out.println("NO");
		        }
		       
		    
		     
		}
	}
}

Problem solution in C++.

#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
	    int n , x , y;
	    cin>>n>>x>>y;
	    if(y%x==0){
	        cout<<"Yes"<<endl;
	        
	    }
	    else{
	        cout<<"No"<<endl;
	    }
	
}
return 0;
}

Problem solution in C.

#include <stdio.h>

int main(void) {
	// your code goes here
	int t,n,x,y;
	scanf("%d",&t);
	while(t--)
	{
	    scanf("%d%d%d",&n,&x,&y);
	    if(y%x!=0)
	    printf("no\n");
	    else
	      {
	          if(y/x<=n)
	          printf("yes\n");
	          else
	          printf("no\n");
	      }
	}
	return 0;
}

Post a Comment

0 Comments