View Code of Problem 2594

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner=new Scanner(System.in);
		int t=scanner.nextInt();
		int k=1;
		while(t-->0) {
			int b=scanner.nextInt();
			int l=scanner.nextInt();
			int[] m=new int[b];
			int max=0;
			for(int i=0;i<b;i++) {
				if(i==0) {
					m[i]=scanner.nextInt();
					max=m[i];
				}
				else {
					m[i]=scanner.nextInt();
					max=gcd(max,m[i]);
				}
			}
			int ans=0;
			while(l>0) {
				for(int i=0;i<b&&l>0;i++) {
					ans=i;
					l-=max/m[i];
				}
			}
			System.out.println("Case #"+(k++)+": "+(ans+1));
			
		}
	}
	
	public static int gcd(int a,int b) {
		int i=a,j=b;
		if(a<b) {
			int t=a;
			a=b;
			b=t;
		}
		while(b!=0) {
			int t=a%b;
			a=b;
			b=t;
		}
		return i*j/a;
	}

}

Double click to view unformatted code.


Back to problem 2594