結果

問題 No.1409 Simple Math in yukicoder
ユーザー koba-e964koba-e964
提出日時 2021-11-01 16:20:56
言語 Rust
(1.77.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 3,168 bytes
コンパイル時間 3,266 ms
コンパイル使用メモリ 179,336 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 13:39:13
合計ジャッジ時間 27,952 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 6 ms
5,376 KB
testcase_29 AC 6 ms
5,376 KB
testcase_30 AC 6 ms
5,376 KB
testcase_31 AC 7 ms
5,376 KB
testcase_32 AC 6 ms
5,376 KB
testcase_33 AC 7 ms
5,376 KB
testcase_34 AC 7 ms
5,376 KB
testcase_35 AC 6 ms
5,376 KB
testcase_36 AC 7 ms
5,376 KB
testcase_37 AC 12 ms
5,376 KB
testcase_38 AC 12 ms
5,376 KB
testcase_39 AC 11 ms
5,376 KB
testcase_40 AC 11 ms
5,376 KB
testcase_41 AC 13 ms
5,376 KB
testcase_42 AC 12 ms
5,376 KB
testcase_43 AC 11 ms
5,376 KB
testcase_44 AC 11 ms
5,376 KB
testcase_45 AC 12 ms
5,376 KB
testcase_46 AC 12 ms
5,376 KB
testcase_47 AC 12 ms
5,376 KB
testcase_48 AC 11 ms
5,376 KB
testcase_49 AC 12 ms
5,376 KB
testcase_50 AC 12 ms
5,376 KB
testcase_51 AC 12 ms
5,376 KB
testcase_52 AC 12 ms
5,376 KB
testcase_53 AC 11 ms
5,376 KB
testcase_54 AC 12 ms
5,376 KB
testcase_55 AC 13 ms
5,376 KB
testcase_56 AC 11 ms
5,376 KB
testcase_57 AC 11 ms
5,376 KB
testcase_58 AC 12 ms
5,376 KB
testcase_59 AC 11 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}

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)*}
    };
}

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); }
impl<T: PartialOrd> Change for T {
    fn chmax(&mut self, x: T) { if *self < x { *self = x; } }
    fn chmin(&mut self, x: T) { if *self > x { *self = x; } }
}

fn powmod(x: i64, mut e: i64, m: i64) -> i64 {
    let mut sum = 1;
    let mut cur = x % m;
    while e > 0 {
        if e % 2 != 0 {
            sum = sum * cur % m;
        }
        cur = cur * cur % m;
        e /= 2;
    }
    sum
}

// Find a generator of (Z/pZ)^\times
fn gen_zpz(p: i64) -> i64 {
    let mut v = p - 1;
    let mut f = 2;
    let mut fs = vec![];
    while v >= f * f {
        if v % f == 0 {
            fs.push(f);
            while v % f == 0 { v /= f; }
        }
        f += 1;
    }
    if v > 1 {
        fs.push(v);
    }
    let mut g = 2;
    loop {
        if fs.iter().all(|&x| powmod(g, (p - 1) / x, p) != 1) {
            return g;
        }
        g += 1;
    }
}

// Tags: generators-of-cyclic-groups
fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    #[allow(unused)]
    macro_rules! putvec {
        ($v:expr) => {
            for i in 0..$v.len() {
                puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
            }
        }
    }
    input! {
        t: usize,
        vx: [(i64, i64); t],
    }
    for (v, x) in vx {
        let p = v * x + 1;
        let g = gen_zpz(p);
        let k = powmod(g, v, p);
        let mut ans = vec![];
        let mut c = 1;
        for _ in 0..x {
            ans.push(c);
            c = c * k % p;
        }
        ans.sort_unstable();
        putvec!(ans);
    }
}
0