結果

問題 No.741 AscNumber(Easy)
ユーザー nanaenanae
提出日時 2018-12-31 20:32:33
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 104,696 KB
実行使用メモリ 19,232 KB
最終ジャッジ日時 2024-06-13 02:26:44
合計ジャッジ時間 2,203 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum long mod = 10 ^^ 9 + 7;

void main() {
    int n;
    scan(n);

    auto f = new long[](n + 100);
    f[0] = f[1] = 1;
    foreach (i ; 2 .. n + 100) {
        f[i] = f[i-1] * i % mod;
    }
    auto rf = new long[](n + 100);
    rf[n + 99] = powmod(f[n + 99], mod - 2, mod);
    foreach_reverse (i ; 0 .. n + 99) {
        rf[i] = rf[i+1] * (i+1) % mod;
    }

    long comb(int n, int k) {
        return f[n] * rf[k] % mod * rf[n-k] % mod;
    }

    long ans;

    foreach (i ; 0 .. 10) {
        debug {
            writeln(comb(n - 1 + i, i));
        }
        ans += comb(n - 1 + i, i);
        ans %= mod;
    }

    writeln(ans);
}

long powmod(long x, long y, long mod) {
    return y > 0 ? powmod(x, y>>1, mod)^^2 % mod * x^^(y&1) % mod : 1;
}




























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0