import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int q = sc.nextInt(); List> current = new ArrayList<>(); for (int i = 0; i <= 100000; i++) { current.add(new ArrayList<>()); } for (int i = 1; i <= 100000; i++) { for (int j = 1; j * i <= 100000; j++) { current.get(j * i).add(i); } } Map> places = new HashMap<>(); for (int i = 1; i <= n; i++) { int a = sc.nextInt(); for (int x : current.get(a)) { if (!places.containsKey(x)) { places.put(x, new TreeMap<>()); places.get(x).put(0, 0); } places.get(x).put(i, places.get(x).size()); } } String result = IntStream.range(0, q).mapToObj(i -> getCount(places, sc.nextInt(), sc.nextInt(), sc.nextInt())) .collect(Collectors.joining("\n")); System.out.println(result); } static String getCount(Map> places, int left, int right, int value) { if (places.containsKey(value)) { return String.valueOf(places.get(value).floorEntry(right).getValue() - places.get(value).lowerEntry(left).getValue()); } else { return "0"; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }