結果

問題 No.1243 約数加算
ユーザー どららどらら
提出日時 2020-10-02 22:55:11
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,314 bytes
コンパイル時間 3,057 ms
コンパイル使用メモリ 141,296 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-24 22:28:44
合計ジャッジ時間 3,103 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,504 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
use std::str::FromStr;

fn calc(x: i64, mx: i64) -> i64 {
    if x % 2 == 1 {
        return 1;
    }
    let mut ret: i64 = 0;
    let mut i: i64 = 1;
    while i <= x {
        if x % i == 0 {
            if i <= mx && i > ret {
                ret = i
            }
            if x / i <= mx && x / i > ret {
                ret = x / i
            }
        }
        i *= 2;
    }
    ret
}

fn solve(a: i64, b: i64) {
    let mut ret: Vec<i64> = Vec::new();

    let mut x = a;
    while x != b {
        if x + x <= b {
            ret.push(x);
            x += x;
        } else {
            let y = calc(x, b - x);
            ret.push(y);
            x += y;
        }
    }

    println!("{}", ret.len());
    for i in 0..ret.len() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ret[i]);
    }
    println!();
}

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|x| i32::from_str(x).unwrap());
    let t = itr.next().unwrap();

    for _i in 0..t {
        s.clear();
        stdin().read_line(&mut s).ok();
        let mut itr = s.split_whitespace().map(|x| i64::from_str(x).unwrap());
        let (a, b) = (itr.next().unwrap(), itr.next().unwrap());

        solve(a, b);
    }
}
0