Machines
Samuel owns a shoe factory where there are N different machines operated for
N different purposes. Each machine has its own motor. In order to avoid
resonance, the rotation speed of any 2 machines should at least differ by 2
units. The rotation speed can only be in integer units and the maximum rotation
speed of any motor is X units. Glven minimum rotation speed of any motor to
be 1 unit, you have to help Sam find out the number of different ways he can
configure the speed of the motors.
Input Specification:
input1: N, denoting the number of machines.
input2: X, denoting the maximum speed of the motor.
Output Specification:
Your function should return the total number of configuration
modulus 10^4.
Answers
Answer:
- The total number of machine = 5
- Maximum speed of the motor = 20
- Configuration module = 6000
Explanation:
Given:
- There are N different machines operated for N different purposes.
- he rotation speed can only be in integer units and the maximum rotation speed of any motor is X units.
Algorithm:
import java.util.Scanner;
public class Main {
public static int totalNumber(int n, int x) {
int engines = x / 2 + (x % 2 != 0 ? 1 : 0);
if (engines < n) {
return 0;
} else {
int total = engines;
for (int i = 1; i < n; i++) {
total = (total * --engines) % 10000;
}
return total;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("N:");
int n = in.nextInt();
System.out.println("X:");
int x = in.nextInt();
System.out.println(totalNumber(n, x));
}
}
Final answer:
The function should return the total number of configuration modulus is 6000
#SPJ3