Submission #2973387

Source Code Expand

Copy
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn ksum(x:i32) -> i32 {
    let mut y = 0;
    let mut x = x;
    while x > 0 {
        y += x % 10;
        x /= 10;
    }
    y
}
fn solve(n:i32, a:i32, b:i32) -> i32 {
    let mut ans = 0;
    for i in 1..n+1 {
        let y = ksum(i);
        if a <= y && y <= b {
            ans += i;
        }
    }
    ans
}
fn main() {
    let nab = read_vec::<i32>();
    println!("{}", solve(nab[0], nab[1], nab[2]));
}

Submission Info

Submission Time
Task ABC083B - Some Sums
User naoya_t
Language Rust (1.15.1)
Score 200
Code Size 743 Byte
Status
Exec Time 2 ms
Memory 4352 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 200 / 200 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 2 ms 4352 KB
02.txt 2 ms 4352 KB
03.txt 2 ms 4352 KB
04.txt 2 ms 4352 KB
05.txt 2 ms 4352 KB
06.txt 2 ms 4352 KB
07.txt 2 ms 4352 KB
08.txt 2 ms 4352 KB
s1.txt 2 ms 4352 KB
s2.txt 2 ms 4352 KB
s3.txt 2 ms 4352 KB