結果

問題 No.1339 循環小数
ユーザー tonyu0tonyu0
提出日時 2021-01-15 22:30:09
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 966 bytes
コンパイル時間 13,239 ms
コンパイル使用メモリ 378,204 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-05-05 00:32:20
合計ジャッジ時間 15,838 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,040 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 24 ms
5,376 KB
testcase_12 AC 28 ms
5,376 KB
testcase_13 AC 20 ms
5,376 KB
testcase_14 AC 22 ms
5,376 KB
testcase_15 AC 21 ms
5,376 KB
testcase_16 AC 18 ms
5,376 KB
testcase_17 AC 26 ms
5,376 KB
testcase_18 AC 16 ms
5,376 KB
testcase_19 AC 18 ms
5,376 KB
testcase_20 AC 15 ms
5,376 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn f(x: usize, n: usize) -> usize {
    x * 10 % n
}

fn cycle(n: usize) -> usize {
    let mut osoi = 10;
    let mut hayai = f(10, n);
    while osoi != hayai {
        osoi = f(osoi, n);
        hayai = f(f(hayai, n), n);
    }

    let mut len = 1;
    hayai = f(hayai, n);
    while osoi != hayai {
        len += 1;
        hayai = f(hayai, n);
    }
    len
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let t: usize = itr.next().unwrap().parse().unwrap();
    for _ in 0..t {
        let n: usize = itr.next().unwrap().parse().unwrap();
        // 10^x mod nの最小循環
        let mut m = n;
        while m % 2 == 0 {
            m /= 2;
        }
        while m % 5 == 0 {
            m /= 5;
        }
        if m == 1 {
            println!("1");
            continue;
        }
        println!("{}", cycle(n));
    }
}
0