Chef Chick Codechef Solution

Hello Programmers In this post, you will know how to solve the Chef Chick Codechef Solution.

Chef Chick Codechef Solution
Chef Chick Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

Chef Chick loves to jump a lot. Once, it realised that it was on an infinitely long road, and decided to travel along this road by jumping.

Let’s view the road as the xx-axis in a 1D coordinate system. Initially, Chef Chick is at the coordinate x=0x=0, and it wants to move only in the positive xx-direction. Moreover, Chef Chick has NN favourite integers a1,a2,…,aNa1,a2,…,aN, and it wants to jump on the coordinates that are multiples of these favourite numbers — when its current position is xx, it jumps to the smallest coordinate y>xy>x such that yy is an integer multiple of at least one of the values a1,a2,…,aNa1,a2,…,aN; the length of such a jump is y−xy−x.

This way, Chef Chick keeps jumping along the road forever in the positive xx-direction. You need to find the length of the longest jump it will make, i.e. the largest integer dd such that Chef Chick makes at least one jump with length dd and never makes any jump with a greater length. It can be proved that such an integer always exists.

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first line of each test case contains a single integer NN.
  • The second line contains NN space-separated integers a1,a2,…,aNa1,a2,…,aN.

Output

For each test case, print a single line containing one integer — the length of the longest jump that Chick will make.

Constraints

  • 1≤T≤1001≤T≤100
  • 1≤N≤1001≤N≤100
  • 1≤ai≤1051≤ai≤105 for each valid ii
  • a1,a2,…,aNa1,a2,…,aN are pairwise distinct

Sample Input 1 

1
2
2 3

Sample Output 1 

2

Explanation

Example case 1: The sequence of coordinates on which Chef Chick would jump starts with (0,2,3,4,6,…)(0,2,3,4,6,…). A longest jump is e.g. from 44 to 66, with length 22

Chef Chick CodeChef Solution in JAVA

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
	{
	    Scanner sc=new Scanner(System.in);
	    int t=sc.nextInt();
	    while(t-->0){
	        int n=sc.nextInt();
	        int a[]=new int[n];
	        for(int i=0;i<n;i++){
	            a[i]=sc.nextInt();
	        }
	        Arrays.sort(a);
	        System.out.println(a[0]);
	    }
		// your code goes here
	}
}
Ezoicreport this ad

Chef Chick CodeChef Solution in CPP

#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,min,k;
        cin>>n>>min;
        for(int i=1;i<n;i++){
            cin>>k;
            if(k<min)
            min=k;
        }
        cout<<min<<endl;
    }
    return 0;
}

Chef Chick CodeChef Solution in Python

# cook your dish here
for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    l.sort()
    print(l[0])

Disclaimer: The above Problem (Chef Chick) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Chef and Socks Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad