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(); Map> places = new HashMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); for (int j = 1; j <= Math.sqrt(x); j++) { if (x % j == 0) { if (!places.containsKey(j)) { places.put(j, new TreeMap<>()); } places.get(j).put(i, null); if (j * j == x) { continue; } if (!places.containsKey(x / j)) { places.put(x / j, new TreeMap<>()); } places.get(x / j).put(i, null); } } } for (TreeMap current : places.values()) { int idx = 0; for (int x : current.keySet()) { current.put(x, idx++); } } String result = IntStream.range(0, q).mapToObj(i -> { int left = sc.nextInt() - 1; int right = sc.nextInt() - 1; int x = sc.nextInt(); if (!places.containsKey(x) || places.get(x).firstKey() > right || places.get(x).lastKey() < left) { return "0"; } else { return String.valueOf(places.get(x).floorEntry(right).getValue() - places.get(x).ceilingEntry(left).getValue() + 1); } }).collect(Collectors.joining("\n")); System.out.println(result); } } 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(); } } }