QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#511615 | #9167. Coprime Array | ucup-team635# | AC ✓ | 113ms | 2328kb | Rust | 3.1kb | 2024-08-10 08:21:21 | 2024-10-14 07:51:44 |
Judging History
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: i64,
x: i64,
}
let cond = |v: i64| -> bool {
v.abs() <= 1000000000 && binary_gcd(v.abs() as u64, x.abs() as u64) == 1
};
let up = 1000000;
let ans = (|| -> Vec<i64> {
if cond(s) {
return vec![s];
}
for i in -up..up {
if cond(s + i) && cond(-i) {
return vec![s + i, -i];
}
}
for i in -up..up {
if cond(s + i - 1) && cond(i) && cond(1) {
return vec![s + i - 1, 1, -i];
}
}
todo!()
})();
let sum = ans.iter().sum::<i64>();
assert!(sum == s);
for a in ans.iter() {
assert!(binary_gcd(a.abs() as u64, x as u64) == 1);
}
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 ----------
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 58ms
memory: 2220kb
input:
9 6
output:
3 -999989 1 999997
result:
ok Correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 2252kb
input:
14 34
output:
2 -999985 999999
result:
ok Correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 2116kb
input:
1000000000 223092870
output:
2 999000017 999983
result:
ok Correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 2052kb
input:
2 1000000000
output:
2 -999997 999999
result:
ok Correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 2088kb
input:
649557664 933437700
output:
2 648557681 999983
result:
ok Correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 2120kb
input:
33396678 777360870
output:
2 32396681 999997
result:
ok Correct
Test #7:
score: 0
Accepted
time: 105ms
memory: 2216kb
input:
48205845 903124530
output:
3 47205847 1 999997
result:
ok Correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 2208kb
input:
251037078 505905400
output:
2 250037087 999991
result:
ok Correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 2136kb
input:
30022920 172746860
output:
2 29022923 999997
result:
ok Correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 2320kb
input:
63639298 808058790
output:
2 62639351 999947
result:
ok Correct
Test #11:
score: 0
Accepted
time: 104ms
memory: 2328kb
input:
76579017 362768406
output:
3 75579019 1 999997
result:
ok Correct
Test #12:
score: 0
Accepted
time: 113ms
memory: 2124kb
input:
40423669 121437778
output:
3 39423673 1 999995
result:
ok Correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 2096kb
input:
449277309 720915195
output:
2 448277311 999998
result:
ok Correct
Test #14:
score: 0
Accepted
time: 108ms
memory: 2260kb
input:
81665969 919836918
output:
3 80665973 1 999995
result:
ok Correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 2184kb
input:
470578680 280387800
output:
2 469578691 999989
result:
ok Correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 2100kb
input:
58450340 803305503
output:
2 57450340 1000000
result:
ok Correct
Test #17:
score: 0
Accepted
time: 104ms
memory: 2120kb
input:
125896113 323676210
output:
3 124896121 1 999991
result:
ok Correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 2252kb
input:
381905348 434752500
output:
2 380905351 999997
result:
ok Correct
Test #19:
score: 0
Accepted
time: 0ms
memory: 2284kb
input:
78916498 653897673
output:
1 78916498
result:
ok Correct
Test #20:
score: 0
Accepted
time: 99ms
memory: 2060kb
input:
35787885 270845190
output:
3 34787887 1 999997
result:
ok Correct
Extra Test:
score: 0
Extra Test Passed