use std::io::{Read,stdin}; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); macro_rules! get { ($t:ty) => (get().parse::<$t>().unwrap()); () => (get!(i64)); } let p = get!(); let mut tb = vec![0; 1 + p as usize]; for i in 1..=p { let j = i as usize; tb[j] += tb[j - 1] + p % i; } let q = get!(); for _ in 0..q { let li = get!(); let ri = get!(); if p < li { let ans = (ri - li + 1) * p; println!("{}", ans); } else if p < ri { let mut ans = (ri - p) * p; ans += tb[p as usize] - tb[li as usize - 1]; println!("{}", ans); } else { let ans = tb[ri as usize] - tb[li as usize - 1]; println!("{}", ans); } } }