Submission #3260062

Source Code Expand

Copy
```#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define Itr(i, c) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 510000;
const int INF = 999999999;
const int MOD = 1000000007;

vector<pair<ll, ll> > prime_factorize(ll n) {
vector<pair<ll, ll> > res;
for (ll p = 2; p * p <= n; ++p) {
if (n % p != 0) continue;
int num = 0;
while (n % p == 0) { ++num; n /= p; }
res.pb(make_pair(p, num));
}
if (n != 1) res.pb(make_pair(n, 1));
return res;
}

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}

// 二項係数計算
ll COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
int n, m; cin >> n >> m;
n--;
ll ans = 1;
COMinit();
vector<pair<ll, ll> > vec = prime_factorize(m);
Rep(i, vec.size()){
ll t = COM(vec[i].second + n, n);
ans = (ans * t) % MOD;
}
cout << ans << endl;
return 0;
}
```

#### Submission Info

Submission Time 2018-09-23 23:36:09+0900 D - Factorization niimi C++14 (GCC 5.4.1) 400 1583 Byte AC 11 ms 12160 KB

#### Test Cases

Set Name Score / Max Score Test Cases
All 400 / 400 0_small_1, 0_small_2, 0_small_3, 1_large_1, 1_large_2, 1_large_3, 2_large_1, 2_large_2, 3_prime_1, 3_prime_10, 3_prime_11, 3_prime_12, 3_prime_13, 3_prime_14, 3_prime_15, 3_prime_16, 3_prime_17, 3_prime_18, 3_prime_19, 3_prime_2, 3_prime_20, 3_prime_21, 3_prime_22, 3_prime_3, 3_prime_4, 3_prime_5, 3_prime_6, 3_prime_7, 3_prime_8, 3_prime_9, 4_hand_1, 4_hand_2, 4_hand_3, sample_01, sample_02, sample_03
Sample 0 / 0 sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_small_1 11 ms 12160 KB
0_small_2 11 ms 12160 KB
0_small_3 11 ms 12160 KB
1_large_1 11 ms 12160 KB
1_large_2 11 ms 12160 KB
1_large_3 10 ms 12160 KB
2_large_1 11 ms 12160 KB
2_large_2 10 ms 12160 KB
3_prime_1 11 ms 12160 KB
3_prime_10 10 ms 12160 KB
3_prime_11 11 ms 12160 KB
3_prime_12 11 ms 12160 KB
3_prime_13 11 ms 12160 KB
3_prime_14 11 ms 12160 KB
3_prime_15 11 ms 12160 KB
3_prime_16 11 ms 12160 KB
3_prime_17 11 ms 12160 KB
3_prime_18 11 ms 12160 KB
3_prime_19 10 ms 12160 KB
3_prime_2 11 ms 12160 KB
3_prime_20 11 ms 12160 KB
3_prime_21 11 ms 12160 KB
3_prime_22 11 ms 12160 KB
3_prime_3 11 ms 12160 KB
3_prime_4 11 ms 12160 KB
3_prime_5 11 ms 12160 KB
3_prime_6 11 ms 12160 KB
3_prime_7 11 ms 12160 KB
3_prime_8 11 ms 12160 KB
3_prime_9 11 ms 12160 KB
4_hand_1 11 ms 12160 KB
4_hand_2 11 ms 12160 KB
4_hand_3 11 ms 12160 KB
sample_01 11 ms 12160 KB
sample_02 11 ms 12160 KB
sample_03 10 ms 12160 KB