Submission #7744809


Source Code Expand

Copy
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

use std::collections::HashSet;

fn yakusu(a: i64, b: i64) -> usize {
    let mut a = a;
    let mut b = b;
    let mut s = HashSet::new();
    let mut common = HashSet::new();
    for p in 2..a {
        if a % p == 0 {
            s.insert(p);
        }
        while a % p == 0 { a /= p }
        if p * p > a && a > 2 {
            s.insert(a);
            break
        }
    }
    for p in 2..b {
        if b % p == 0 {
            if s.contains(&p) {
                common.insert(p);
            }
        }
        while b % p == 0 { b /= p }
        if p * p > b && b > 2 {
            if s.contains(&p) {
                common.insert(p);
            }
            break
        }
    }
    common.len()
}

fn main() {
    let mut sc = Scanner::new();
    let a: i64 = sc.cin();
    let b: i64 = sc.cin();
    put!(yakusu(a, b) + 1);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}

Submission Info

Submission Time
Task D - Disjoint Set of Common Divisors
User cympfh
Language Rust (1.15.1)
Score 0
Code Size 2739 Byte
Status WA
Exec Time 2103 ms
Memory 4352 KB

Compile Error

warning: unknown lint: `unused_macros`, #[warn(unknown_lints)] on by default
 --> ./Main.rs:1:26
  |
1 | #![allow(unused_imports, unused_macros, dead_code)]
  |                          ^^^^^^^^^^^^^

Judge Result

Set Name All Sample
Score / Max Score 0 / 400 0 / 0
Status
AC × 9
WA × 12
TLE × 5
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_20, testcase_21, testcase_22, testcase_23
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 2 ms 4352 KB
sample_02 AC 2 ms 4352 KB
sample_03 AC 2 ms 4352 KB
testcase_01 AC 7 ms 4352 KB
testcase_02 AC 5 ms 4352 KB
testcase_03 WA 11 ms 4352 KB
testcase_04 WA 2 ms 4352 KB
testcase_05 WA 2 ms 4352 KB
testcase_06 AC 2 ms 4352 KB
testcase_07 TLE 2103 ms 4352 KB
testcase_08 AC 2 ms 4352 KB
testcase_09 AC 4 ms 4352 KB
testcase_10 WA 2 ms 4352 KB
testcase_11 WA 2 ms 4352 KB
testcase_12 WA 2 ms 4352 KB
testcase_13 AC 2 ms 4352 KB
testcase_14 TLE 2103 ms 4352 KB
testcase_15 WA 2 ms 4352 KB
testcase_16 TLE 2103 ms 4352 KB
testcase_17 TLE 2103 ms 4352 KB
testcase_18 TLE 2103 ms 4352 KB
testcase_19 WA 2 ms 4352 KB
testcase_20 WA 5 ms 4352 KB
testcase_21 WA 4 ms 4352 KB
testcase_22 WA 6 ms 4352 KB
testcase_23 WA 30 ms 4352 KB