#![allow(unused_imports)] #![allow(unused_macros)] #![allow(non_snake_case)] use proconio::marker::{Bytes, Chars, Isize1, Usize1}; use proconio::{fastout, input, input_interactive}; const BUCKET_SIZE: usize = 200; #[fastout] fn main() { input! { N: usize, Q: usize, A: [usize; N], } let bucket_memo = { let mut memo = mat![0; (N + BUCKET_SIZE - 1) / BUCKET_SIZE; 100_001]; for (i, &a) in A.iter().enumerate() { let bucket = i / BUCKET_SIZE; for d in 1.. { if d * d > a { break; } if a % d == 0 { memo[bucket][d] += 1; if a / d != d { memo[bucket][a / d] += 1; } } } } memo }; for _ in 0..Q { input! { L: Usize1, R: Usize1, K: usize, } let l_bucket = L / BUCKET_SIZE; let r_bucket = R / BUCKET_SIZE; let memo_ans = (l_bucket + 1..r_bucket).map(|i| bucket_memo[i][K]).sum::(); let left_ans = (L..((l_bucket+1)*BUCKET_SIZE).min(R+1)).map(|i| (A[i] % K == 0) as usize).sum::(); let right_ans = if l_bucket < r_bucket { ((r_bucket*BUCKET_SIZE).max(L)..(R+1)).map(|i| (A[i] % K == 0) as usize).sum::() } else { 0 }; println!("{}", memo_ans + left_ans + right_ans); } } #[macro_export] macro_rules! mat { ($($e:expr),*) => { vec![$($e),*] }; ($($e:expr,)*) => { vec![$($e),*] }; ($e:expr; $d:expr) => { vec![$e; $d] }; ($e:expr; $d:expr $(; $ds:expr)+) => { vec![mat![$e $(; $ds)*]; $d] }; } #[macro_export] macro_rules! chmin { ($a:expr, $b:expr) => { if $a > $b { $a = $b; true } else { false } }; } #[macro_export] macro_rules! chmax { ($a:expr, $b:expr) => { if $a < $b { $a = $b; true } else { false } }; } /// https://maguro.dev/debug-macro/ #[macro_export] macro_rules! debug { ($($a:expr),* $(,)*) => { #[cfg(debug_assertions)] eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*); }; }