const MOD: i64 = 1_000_000_007; fn solve(a: i64, N: i64) -> i64 { let mut n1 = ((a + 1) / 2) + 1; let mut answer = 0; let mut low = 1; for i in 1..=std::cmp::min(n1, N) { let x = a * i; let mut high = 1_000_000_000; while high - low > 1 { let mid = (high + low) / 2; if mid * mid <= x { low = mid; } else { high = mid; } } let v = if high * high <= x { high } else { low }; answer = (answer + v) % MOD; low = v; } // 最上位から low = 0; let mut high = 1_000_000_000; while high - low > 1 { let mid = (high + low) / 2; if mid * mid <= a * N { low = mid; } else { high = mid; } } let mut v = if high * high <= a * N { high } else { low }; let mut n0 = N; while n1 < n0 { let mut x = (v * v) / a; if x * a < v * v { x += 1; } x = std::cmp::max(n1 + 1, x); let y = (n0 - x + 1) % MOD; answer = (answer + (y * v) % MOD) % MOD; v -= 1; n0 = x - 1; } answer } fn main() { use std::io::{self, BufRead}; let stdin = io::stdin(); let mut reader = stdin.lock().lines(); let T: i64 = reader.next().unwrap().unwrap().trim().parse().unwrap(); let mut answers = Vec::new(); for _ in 0..T { let line = reader.next().unwrap().unwrap(); let mut iter = line.split_whitespace(); let a: i64 = iter.next().unwrap().parse().unwrap(); let N: i64 = iter.next().unwrap().parse().unwrap(); let ans = solve(a, N); answers.push(ans); } for ans in answers { println!("{}", ans); } }