fn main() { let stdin = std::io::read_to_string(std::io::stdin()).unwrap(); let mut stdin = stdin.split_ascii_whitespace(); let n: usize = stdin.next().unwrap().parse().unwrap(); let p: Vec = (0..n) .map(|_| stdin.next().unwrap().parse().unwrap()) .collect(); println!("{}", output(solve(p))); } fn prepare(max_n: usize) -> Vec> { let mut divisors_of = vec![Vec::new(); max_n + 1]; for i in 1..=max_n { for j in (1..).take_while(|&j| i * j <= max_n) { divisors_of[i * j].push(i as u32); } } divisors_of } fn solve(p: Vec) -> Vec { let divisors_of = prepare(200_000); let mut is_visited = vec![false; p.len()]; let mut ans = vec![0; p.len()]; for i in 0..p.len() { if !is_visited[i] { let mut count_of = std::collections::HashMap::new(); let mut cur = i; while !is_visited[cur] { is_visited[cur] = true; for &j in &divisors_of[cur.abs_diff((p[cur] - 1) as usize)] { match count_of.get_mut(&j) { Some(target) => { *target += 1; } None => { count_of.insert(j, 1_u32); } } } cur = (p[cur] - 1) as usize; } for (value, count) in count_of.into_iter() { ans[value as usize] += count - 1; } } } ans } fn output(ans: Vec) -> String { ans.into_iter() .skip(1) .map(|x| x.to_string()) .collect::>() .join("\n") }