結果

問題 No.502 階乗を計算するだけ
ユーザー tabataba
提出日時 2024-08-05 10:40:27
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 42 ms / 1,000 ms
コード長 3,276 bytes
コンパイル時間 11,624 ms
コンパイル使用メモリ 396,432 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-05 10:40:42
合計ジャッジ時間 13,628 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 0 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 0 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 0 ms
6,940 KB
testcase_22 AC 5 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 4 ms
6,944 KB
testcase_31 AC 3 ms
6,944 KB
testcase_32 AC 25 ms
6,940 KB
testcase_33 AC 42 ms
6,940 KB
testcase_34 AC 39 ms
6,940 KB
testcase_35 AC 40 ms
6,940 KB
testcase_36 AC 22 ms
6,944 KB
testcase_37 AC 41 ms
6,940 KB
testcase_38 AC 18 ms
6,944 KB
testcase_39 AC 36 ms
6,940 KB
testcase_40 AC 7 ms
6,940 KB
testcase_41 AC 1 ms
6,944 KB
testcase_42 AC 0 ms
6,940 KB
testcase_43 AC 1 ms
6,944 KB
testcase_44 AC 1 ms
6,940 KB
testcase_45 AC 1 ms
6,944 KB
testcase_46 AC 1 ms
6,940 KB
testcase_47 AC 1 ms
6,940 KB
testcase_48 AC 1 ms
6,940 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 1 ms
6,940 KB
testcase_51 AC 0 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused imports: `HashMap`, `HashSet`
 --> src/main.rs:1:24
  |
1 | use std::collections::{HashMap, HashSet};
  |                        ^^^^^^^  ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unnecessary parentheses around `for` iterator expression
  --> src/main.rs:20:14
   |
20 |     for i in (r.0..=n) {
   |              ^       ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
20 -     for i in (r.0..=n) {
20 +     for i in r.0..=n {
   |

ソースコード

diff #

use std::collections::{HashMap, HashSet};

fn main() {
    proconio::input! {
        n: u64,
    }
    if n >= 1000000007 {
        println!("0");
        return;
    }
    //let mut memo = vec![];
    let r = RESUME
        .iter()
        .copied()
        .rev()
        .skip_while(|x| x.0 > n)
        .next()
        .unwrap_or((1, 1));
    let mut x = r.1;
    for i in (r.0..=n) {
        x = (x * i) % 1000000007;
    }
    println!("{x}");
}

const RESUME: [(u64, u64); 100] = [
    (10000000, 250015370),
    (20000000, 777847830),
    (30000000, 64381203),
    (40000000, 129227219),
    (50000000, 664720426),
    (60000000, 220551652),
    (70000000, 805011386),
    (80000000, 71626953),
    (90000000, 368173468),
    (100000000, 388742192),
    (110000000, 633943807),
    (120000000, 546160751),
    (130000000, 248863345),
    (140000000, 642800490),
    (150000000, 227253170),
    (160000000, 217956259),
    (170000000, 448399780),
    (180000000, 343122361),
    (190000000, 203128902),
    (200000000, 904824556),
    (210000000, 976400196),
    (220000000, 409788350),
    (230000000, 969665321),
    (240000000, 942841378),
    (250000000, 78633765),
    (260000000, 46429647),
    (270000000, 419288563),
    (280000000, 622773713),
    (290000000, 43950471),
    (300000000, 158036420),
    (310000000, 539867530),
    (320000000, 629028067),
    (330000000, 98679775),
    (340000000, 181067811),
    (350000000, 577131628),
    (360000000, 448714637),
    (370000000, 274699378),
    (380000000, 172718980),
    (390000000, 524877565),
    (400000000, 132400827),
    (410000000, 283566441),
    (420000000, 299777072),
    (430000000, 688241748),
    (440000000, 422054382),
    (450000000, 789638131),
    (460000000, 386613162),
    (470000000, 219084929),
    (480000000, 375238282),
    (490000000, 270146387),
    (500000000, 647619052),
    (510000000, 871756271),
    (520000000, 645927523),
    (530000000, 483519685),
    (540000000, 459833872),
    (550000000, 273602905),
    (560000000, 929096963),
    (570000000, 250231633),
    (580000000, 278589981),
    (590000000, 849449796),
    (600000000, 541794170),
    (610000000, 601214344),
    (620000000, 860331963),
    (630000000, 898831734),
    (640000000, 959047580),
    (650000000, 990713044),
    (660000000, 218658983),
    (670000000, 293444525),
    (680000000, 385243308),
    (690000000, 352821537),
    (700000000, 722869575),
    (710000000, 381109223),
    (720000000, 378511108),
    (730000000, 85458370),
    (740000000, 915965688),
    (750000000, 815695490),
    (760000000, 160874373),
    (770000000, 185206871),
    (780000000, 724450461),
    (790000000, 862837188),
    (800000000, 463715736),
    (810000000, 360855087),
    (820000000, 398991956),
    (830000000, 806738292),
    (840000000, 541775025),
    (850000000, 609437737),
    (860000000, 40420676),
    (870000000, 773978131),
    (880000000, 742263715),
    (890000000, 320097016),
    (900000000, 446595916),
    (910000000, 239856470),
    (920000000, 851897254),
    (930000000, 213673769),
    (940000000, 51083743),
    (950000000, 328555850),
    (960000000, 784853394),
    (970000000, 300038049),
    (980000000, 426045335),
    (990000000, 808434455),
    (1000000000, 900198419),
];
0