C-PROM 2013 (PROBLEM 5: COMPUTATION OF MULTIPLICATION)

PROBLEM 5: COMPUTATION OF MULTIPLICATION


Computes the multiplication of numbers between the two integers (both are inclusive) and the result of the multiplication is divided by 6. The two numbers could be a negative or positive numbers.

Input
The first line of the input contains an integer N (1 ≤ N ≤ 5), the number of test cases. Following the first line are the test cases. Each line in a test case contains a pair of Integer numbers seperated by a space.

The input must be read from standard input.

Output
The output of the program should print the result of the multiplication which divided by 6 and print 0 otherwise.

The output must be written to standard output.

Sample Input
Sample Output

3
3 5
10 11
-3 -1



60
0
-6


Solution : 

import java.util.*;
public class CompMul {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
int x = scn.nextInt();
if(x >= 1 && x<=5) {
for(int b=0;b<x;b++) {
int y = scn.nextInt();
int z = scn.nextInt();
int temp=0;
if(z < y) {
temp=z;
z=y;
y=temp;
}
int total=1;
for(int r=y;r<=z;r++)
total = total*r;
if((total%6)==0)
System.out.println(total);
else
System.out.println("0");
}
}
}
}

Share this

Related Posts

Previous
Next Post »