結果
問題 | No.816 Beautiful tuples |
ユーザー | wh317706 |
提出日時 | 2019-04-19 21:57:12 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 1,500 ms |
コード長 | 4,302 bytes |
コンパイル時間 | 13,968 ms |
コンパイル使用メモリ | 380,176 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 19:04:20 |
合計ジャッジ時間 | 13,465 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 1 ms
6,944 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::io::{stderr, stdin, stdout, BufWriter, StdoutLock, Write}; #[allow(unused_imports)] use std::iter::FromIterator; #[allow(unused_imports)] use std::{i64, u64, usize}; #[allow(unused_macros)] macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; } #[allow(unused_macros)] macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; } #[allow(unused_macros)] macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , [ $ t : tt ] ) => { { let len = read_value ! ( $ next , usize ) ; ( 0 .. len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; } #[allow(dead_code)] struct Writer { s: String, } #[allow(unused_imports)] use std::fmt::Display; #[allow(dead_code)] #[doc = " let mut writer = Writer::new();"] #[doc = " writer.writeln(hoge);"] #[doc = " writer.flush()"] impl Writer { #[allow(dead_code)] pub fn new() -> Writer { Writer { s: String::new() } } #[allow(dead_code)] pub fn flush(&mut self) { print!("{}", self.s); self.s.clear(); } pub fn write<T: Display>(&mut self, x: T) { self.s.push_str(&format!("{}", x)); } pub fn writeln<T: Display>(&mut self, x: T) { self.s.push_str(&format!("{}", x)); self.s.push('\n'); } #[allow(dead_code)] pub fn write_vec<T: Display>(&mut self, xs: &Vec<T>) { if xs.len() == 0 { self.writeln(""); return; } self.write(&format!("{}", xs[0])); for i in 1..xs.len() { self.write(&format!(" {}", xs[i])); } self.writeln(""); } } #[allow(unused_macros)] macro_rules ! dbg { ( $ ( $ a : expr ) ,* ) => { writeln ! ( & mut stderr ( ) , concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) . unwrap ( ) ; } } #[allow(dead_code)] const INF_U: u64 = 1_000_000_000_000_000; #[allow(dead_code)] const INF_I: i64 = 1_000_000_000_000_000; #[allow(dead_code)] pub fn divisor(n: u64) -> Vec<u64> { let mut div: Vec<u64> = Vec::new(); let mut i = 1; while i * i <= n { if n % i == 0 { div.push(i); if i * i != n { div.push(n / i); } } i += 1; } div.sort(); div } #[allow(non_snake_case)] #[allow(dead_code)] fn main() { input! { a: u64, b: u64 } let div = divisor(a + b); let mut c = 0; for d in div { if a != b && b != d && d != a && (a + d) % b == 0 && (b + d) % a == 0 { c = d; } } if c == 0 { println!{"{}", -1}; } else { println!{"{}", c}; } }