Skip to content

Commit

Permalink
past16-open j
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 6, 2024
1 parent ff072b2 commit 24f2884
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions cargo-atcoder-1.70.0/contests/past16-open/src/bin/j.rs
@@ -1,10 +1,58 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn divisors(n: usize) -> Vec<usize> {
let mut d = vec![];
for i in 1.. {
if i * i > n {
break;
}
if n % i == 0 {
d.push(i);
if i != n / i {
d.push(n / i);
}
}
}
d.sort();
d
}

fn gcd(n: usize, m: usize) -> usize {
if m == 0 {
n
} else {
gcd(m, n % m)
}
}

fn main() {
input! {
n: usize,
a: [Usize1; n],
k: usize,
a: [usize; k],
};
let ans = n - a.len();
println!("{}", ans);

let mut b = vec![];
let mut prev = a[0];
for a_i in a.iter().copied().skip(1) {
b.push(a_i - prev);
prev = a_i;
}

let mut g = gcd(b[0], if b.len() == 1 { b[0] } else { b[1] });
for b_i in b {
g = gcd(g, b_i);
}

let mut ans = vec![];
for d in divisors(g) {
if (n - 1) * d >= a[k - 1] - a[0] {
ans.push(d);
}
}

println!("{}", ans.len());
for a in ans {
println!("{}", a);
}
}

0 comments on commit 24f2884

Please sign in to comment.