結果

問題 No.1339 循環小数
ユーザー tonyu0tonyu0
提出日時 2021-01-15 22:39:15
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 934 bytes
コンパイル時間 11,294 ms
コンパイル使用メモリ 377,492 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-05 00:40:29
合計ジャッジ時間 15,516 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 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 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 20 ms
5,376 KB
testcase_12 AC 22 ms
5,376 KB
testcase_13 AC 15 ms
5,376 KB
testcase_14 AC 18 ms
5,376 KB
testcase_15 AC 19 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 24 ms
5,376 KB
testcase_18 AC 14 ms
5,376 KB
testcase_19 AC 14 ms
5,376 KB
testcase_20 AC 13 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 power = 1;
    let mut len = 1;
    let mut slow = 10;
    let mut fast = f(10, n);
    while slow != fast {
        if power == len {
            slow = fast;
            power *= 2;
            len = 0;
        }
        fast = f(fast, n);
        len += 1;
    }
    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();
        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