CSES - Putka Open 2020 – 1/5 - Results
Submission details
Task:Pinot
Sender:Hennkka
Submission time:2020-09-05 18:12:40 +0300
Language:Rust
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED23
#2ACCEPTED77
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Code

use std::io::BufRead;
use std::str::FromStr;

fn solve(a: usize, b: usize) -> usize {
    let mut res = 0;
    let mut a = a;
    let mut b = b;
    if b < a {
        std::mem::swap(&mut a, &mut b);
    }
    while a != 0 {
        let removals = b / a;
        b -= removals * a;
        res += removals;
        std::mem::swap(&mut a, &mut b);
    }
    res
}

fn main() {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let mut lines = stdin.lines();
    let t = usize::from_str(&lines.next().unwrap().unwrap()).unwrap();

    for _ in 0..t {
        let line: Vec<_> = lines
            .next()
            .unwrap()
            .unwrap()
            .split_whitespace()
            .map(|v| usize::from_str(&v).unwrap())
            .collect();
        let (a, b) = (line[0], line[1]);
        println!("{}", solve(a, b));
    }
    // assert_eq!(list.len(), n);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn sample_cases() {
        assert_eq!(solve(3, 10), 6);
        assert_eq!(solve(5, 5), 1);
        assert_eq!(solve(1, 100), 100);
    }

    #[test]
    fn big_case() {
        assert_eq!(solve(1, 1_000_000_000), 1_000_000_000);
    }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
1000
5 90
19 86
66 28
10 47
...

correct output
18
15
9
10
16
...

user output
18
15
9
10
16
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
1 936283842
56227247 73458046
364717918 449812461
158413382 363667122
...

correct output
936283842
167
116
59
158
...

user output
936283842
167
116
59
158
...
Truncated