結果
問題 | No.890 移調の限られた旋法 |
ユーザー | cotton_fn_ |
提出日時 | 2020-02-09 12:01:01 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,865 bytes |
コンパイル時間 | 12,331 ms |
コンパイル使用メモリ | 377,904 KB |
実行使用メモリ | 17,504 KB |
最終ジャッジ日時 | 2024-10-01 05:49:13 |
合計ジャッジ時間 | 14,196 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,820 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,820 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 1 ms
6,820 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 1 ms
6,816 KB |
testcase_13 | AC | 51 ms
17,504 KB |
testcase_14 | AC | 20 ms
9,772 KB |
testcase_15 | WA | - |
testcase_16 | AC | 37 ms
13,584 KB |
testcase_17 | AC | 22 ms
9,652 KB |
testcase_18 | AC | 28 ms
11,204 KB |
testcase_19 | AC | 20 ms
8,000 KB |
testcase_20 | AC | 8 ms
6,820 KB |
testcase_21 | AC | 3 ms
6,820 KB |
testcase_22 | AC | 16 ms
7,828 KB |
testcase_23 | AC | 19 ms
9,252 KB |
testcase_24 | AC | 12 ms
6,816 KB |
testcase_25 | AC | 4 ms
6,820 KB |
testcase_26 | AC | 19 ms
9,436 KB |
testcase_27 | AC | 20 ms
9,444 KB |
testcase_28 | AC | 13 ms
6,820 KB |
testcase_29 | AC | 10 ms
6,820 KB |
testcase_30 | AC | 20 ms
9,104 KB |
testcase_31 | AC | 19 ms
7,884 KB |
testcase_32 | WA | - |
testcase_33 | AC | 43 ms
15,544 KB |
testcase_34 | WA | - |
ソースコード
#![allow(unused)] use std::io::{self, BufRead, Write}; pub struct Input<R> { src: R, buf: Vec<u8>, pos: usize, } impl<R: BufRead> Input<R> { pub fn new(src: R) -> Self { Self { src, buf: Vec::new(), pos: 0, } } pub fn input_bytes(&mut self) -> &[u8] { loop { self.advance_until(|b| b.is_ascii_whitespace()); if self.pos == self.buf.len() { self.buf.clear(); self.src .read_until(b'\n', &mut self.buf) .expect("input error"); self.pos = 0; } else { break; } } let l = self.pos; self.advance_until(|b| !b.is_ascii_whitespace()); &self.buf[l..self.pos] } fn advance_until(&mut self, f: impl Fn(u8) -> bool) { while let Some(b) = self.buf.get(self.pos) { if !f(*b) { break; } self.pos += 1; } } pub fn input<T: std::str::FromStr>(&mut self) -> T where <T as std::str::FromStr>::Err: std::fmt::Debug, { String::from_utf8_lossy(self.input_bytes()) .parse() .expect("parse error") } } pub fn mod_pow(a: i64, b: i64, m: i64) -> i64 { let mut b = b; let mut x = a; let mut y = 1; while b > 0 { if b & 1 == 1 { y = y * x % m; } x = x * x % m; b >>= 1; } y } pub fn mod_inv(x: i64, m: i64) -> i64 { mod_pow(x, m - 2, m) } struct Combination { m: i64, fact: Vec<i64>, } impl Combination { pub fn new(size: usize, m: i64) -> Self { let mut comb = Self { m, fact: Vec::new(), }; comb.resize(size); comb } pub fn resize(&mut self, size: usize) { let old_len = self.fact.len(); self.fact.resize(size + 1, 0); for i in old_len..size + 1 { self.fact[i] = if i == 0 { 1 } else { i as i64 * self.fact[i - 1] % self.m }; } } pub fn fact(&self, x: i64) -> i64 { self.fact[x as usize] } pub fn perm(&self, a: i64, b: i64) -> i64 { if a >= b { self.fact(a) * mod_inv(self.fact(a - b), self.m) % self.m } else { 0 } } pub fn comb(&self, a: i64, b: i64) -> i64 { if a >= b { self.fact(a) * mod_inv(self.fact(b) * self.fact(a - b) % self.m, self.m) % self.m } else { 0 } } } pub fn gcd(x: i64, y: i64) -> i64 { if y > 0 { gcd(y, x % y) } else { x } } fn main() { let stdin = io::stdin(); let mut input = Input::new(stdin.lock()); let stdout = io::stdout(); let mut out = io::BufWriter::new(stdout.lock()); let stderr = io::stderr(); let mut err = io::BufWriter::new(stderr.lock()); const MOD: i64 = 1e9 as i64 + 7; let n = input.input(); let k = input.input(); let g = gcd(n, k); let mut mebious = vec![-2; g as usize + 1]; mebious[0] = 0; mebious[1] = 0; for x in 2..=g as usize { if mebious[x] == -2 { mebious[x] = -1; for d in (2 * x..=g as usize).step_by(x) { mebious[d] = if d % (x * x) == 0 { 0 } else if mebious[d] == -2 { -1 } else { -mebious[d] } } } } let mut ans = 0; let comb = Combination::new(n as usize, MOD); for d in 2..=g { if g % d == 0 { ans += -mebious[d as usize] * comb.comb(n / d, k / d) % MOD; } } ans %= MOD; writeln!(&mut out, "{}", ans); }