CSES - Datatähti 2022 loppu - Results
Submission details
Task:Pallo
Sender:xnor
Submission time:2022-01-22 13:17:19 +0200
Language:Rust
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED35
#3ACCEPTED55
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s2, 3details
#3ACCEPTED0.01 s3details

Code

use std::io::{stdin, BufRead, BufReader};

fn main() {
    let mut stdin = BufReader::new(stdin());
    let mut cur_line = String::new();

    stdin.read_line(&mut cur_line).unwrap();
    let t: usize = cur_line.trim().parse().unwrap();

    for _ in 0..t {
        cur_line.clear();
        stdin.read_line(&mut cur_line).unwrap();
        let nums = cur_line
            .split_whitespace()
            .map(|s| s.parse::<u64>().unwrap())
            .collect::<Vec<_>>();

        if let &[n, m, k] = &nums[..] {
            let x = k / (n - 1) + k / (m - 1) - k / lcm(n - 1, m - 1);
            println!("{}", x);
        }
    }
}

fn lcm(a: u64, b: u64) -> u64 {
    let mut u = a;
    let mut v = b;
    loop {
        u %= v;
        if u == 0 {
            return (a / v) * b;
        }
        v %= u;
        if v == 0 {
            return (a / u) * b;
        }
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
100
10 5 76
9 8 78
8 6 49
3 3 94
...

correct output
25
19
15
47
8
...

user output
25
19
15
47
8
...
Truncated

Test 2

Group: 2, 3

Verdict: ACCEPTED

input
1000
7 5 99033171167123849
6 8 472883555390027162
9 10 258937093512465880
10 6 691774305483997493
...

correct output
33011057055707949
148620545979722822
57541576336103529
199845910473154830
52151060432923288
...

user output
33011057055707949
148620545979722822
57541576336103529
199845910473154830
5215106043292328
...
Truncated

Test 3

Group: 3

Verdict: ACCEPTED

input
1000
816332614 86098803 33572721929...

correct output
4310587870
45982113074
1550250683
717639357
3282221941
...

user output
4310587870
45982113074
1550250683
717639357
3282221941
...
Truncated