結果

問題 No.1243 約数加算
ユーザー どららどらら
提出日時 2020-10-02 23:26:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,601 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 140,548 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 23:39:55
合計ジャッジ時間 1,606 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//use rand::Rng;
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 {
        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 rng = rand::thread_rng();

    for _i in 0..1000 {
        let mut a: i64 = rng.gen_range(1, 1000000000000000000_i64);
        let mut b: i64 = rng.gen_range(1, 1000000000000000000_i64);
        if a > b {
            let c = a;
            a = b;
            b = c;
        }
        println!("{} {}", a, b);
        solve(a, b);
    }
}
*/

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