結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー mugcapmugcap
提出日時 2023-05-28 16:43:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,439 bytes
コンパイル時間 1,309 ms
コンパイル使用メモリ 165,156 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-27 14:09:35
合計ジャッジ時間 2,209 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,504 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/dsu>
// #include <atcoder/modint>
using namespace std;
// using namespace atcoder;
#define SZ(x) (int)(x).size()
#define dout(x) printf("%.10f\n", (double)(x))
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
typedef pair<int, int> P;
typedef pair<long, long> Pl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long>> vvl;

long gcd(long a, long b)
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd(b, a % b);
    }
}

/*  lcm (a, b) : 2整数版
    入力:整数 a, b
    出力:aとbの最小公倍数
*/
long lcm(long a, long b)
{
    long d = gcd(a, b);
    return a / d * b;
}

int main()
{
    long N, P, waru = 1000000007;
    cin >> N >> P;
    long ans = 1, zn = 0, sinans = 1, tasu, zans = 1;

    for (long i = N; i > 0; i--)
    {
        sinans *= i;
        sinans %= waru;
        zans *= i;
        zans %= waru - 1;
        ans = i;
        while (ans % P == 0)
        {
            ans /= P;
            zn++;
            zn %= waru;
        }
    }

    ans = 1;
    tasu = sinans;
    for (long i = 0; ((long)1 << i) <= zans; i++)
    {
        if (((long)1 << i) & zans)
        {
            ans *= tasu;
            ans %= waru;
        }
        tasu *= tasu;
        tasu %= waru;
    }

    long fans = zn * ans;
    fans %= waru;
    cout << fans << endl;

    return 0;
}
0