Import Java.util.HashSet;
Import Java.util.Scanner;
Import Java.util.Set; /** * Xiao Yi recently learned the concept of a set in math class with three characteristics: 1. Certainty 2. Sex 3. Disorder. Xiao Yi's teacher gave the little Yi such a set: S = {p/q | w *≤p≤x, Y≤Q≤Z} * You need to find out how many elements in a collection are based on a given w,x,y,z.
Small Isai Learn the collection also can not solve this complex problem, need you to help him. * * * * @author pomay * */public class Wangyi_gather {public static int gather (int w, int x, int y, int z) {//method one
: Use List first seek p/q, then go heavy//list<double> gather = new arraylist<double> (); for (int i = w; I <= x. i++)//{/for (int j = y; J <= Z; j +)//{//GO heavy//if (!gather.contains (i
* 1.0)/J)//{//Gather.add ((I * 1.0)/j);
}//}//}//Method Two: element unordered, not duplicated, directly with Set set<double> gather = new hashset<double> ();
for (int i = w; I <= x. i++) {for (int j = y; J <= Z; j) {Gather.add ((i * 1.0)/j);
} return Gather.size ();
public static void Main (String args[]) {Scanner sc = new Scanner (system.in); The input includes one line: a total of 4 integers: separated by spaces//W (1≤w≤x) int w = Sc.nextint ();
X (1≤x≤100) int x = Sc.nextint ();
Y (1≤y≤z) int y = Sc.nextint ();
Z (1≤z≤100) int z = Sc.nextint ();
SYSTEM.OUT.PRINTLN (Gather (w, x, Y, z)); }
}