Skip to content

Commit

Permalink
past202209-open i
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Nov 28, 2023
1 parent 0d55b9d commit 80fc40c
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions cargo-atcoder-1.70.0/contests/past202209-open/src/bin/i.rs
@@ -1,10 +1,29 @@
use proconio::{input, marker::Usize1};
use proconio::input;

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

for (n, a, m) in case {
let mut sum_head = 0_usize;
for i in 1..=n.min(m) {
sum_head += (a * i * m - a * i) % m;
}
if n < m {
println!("{}", sum_head);
continue;
}

let times = n / m;
let tail = n - (times * m);
let mut tail_sum = 0_usize;
for i in n - tail + 1..=n {
tail_sum += (a * i * m - a * i) % m;
}

let ans = sum_head * times + tail_sum;
println!("{}", ans);
}
}

0 comments on commit 80fc40c

Please sign in to comment.