QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#511610#9167. Coprime Arrayucup-team635#WA 29ms2140kbRust2.9kb2024-08-10 08:09:292024-08-10 08:09:29

Judging History

你现在查看的是最新测评结果

  • [2024-08-11 17:38:28]
  • hack成功,自动添加数据
  • (/hack/775)
  • [2024-08-10 08:09:29]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:2140kb
  • [2024-08-10 08:09:29]
  • 提交

answer

use std::io::Write;
use std::collections::*;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn main() {
    input! {
        s: u64,
        x: u64,
    }
    let ans = (|| -> Vec<i64> {
        if binary_gcd(s, x) == 1 {
            return vec![s as i64];
        }
        for i in 1..=1000000 {
            if binary_gcd(s + i, x) == 1 && binary_gcd(i, x) == 1 {
                return vec![(s + i) as i64, -(i as i64)];
            }
        }
        for i in 1..=1000000 {
            if binary_gcd(s + i - 1, x) == 1 && binary_gcd(i, x) == 1 {
                return vec![(s + i - 1) as i64, 1i64, -(i as i64)];
            }
        }
        todo!()
    })();
    println!("{}", ans.len());
    for (i, a) in ans.iter().enumerate() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", *a);
    }
    println!();
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------
// ---------- begin binary_gcd ----------
pub fn binary_gcd(a: u64, b: u64) -> u64 {
    if a == 0 || b == 0 {
        return a + b;
    }
    let x = a.trailing_zeros();
    let y = b.trailing_zeros();
    let mut a = a >> x;
    let mut b = b >> y;
    while a != b {
        let x = (a ^ b).trailing_zeros();
        if a < b {
            std::mem::swap(&mut a, &mut b);
        }
        a = (a - b) >> x;
    }
    a << x.min(y)
}
// ---------- end binary_gcd ----------


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 29ms
memory: 2140kb

input:

9 6

output:

3
13 1 -5

result:

ok Correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 2104kb

input:

14 34

output:

2
15 -1

result:

ok Correct

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 2140kb

input:

1000000000 223092870

output:

2
1000000031 -31

result:

wrong answer Integer element a[1] equals to 1000000031, violates the range [-10^9, 10^9]