Submission #7965692


Source Code Expand

Copy
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

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

const int MAX = 210000;
const int MOD = 1000000007;

long long 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;
    }
}
long long 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;
  COMinit();
  cin >> n >> m;
  auto vec = prime_factorize(m);
  ll res = 1;
  for(auto pa:vec){
    int num = pa.second;
    ll tmp = COM(num+n-1,n-1);
    res = (res*tmp)%MOD;
  }
  cout << res << endl;
  return 0;
}

Submission Info

Submission Time
Task D - Factorization
User nakyamurya
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1737 Byte
Status
Exec Time 5 ms
Memory 5120 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 5 ms 5120 KB
0_small_2 5 ms 5120 KB
0_small_3 5 ms 5120 KB
1_large_1 5 ms 5120 KB
1_large_2 5 ms 5120 KB
1_large_3 5 ms 5120 KB
2_large_1 5 ms 5120 KB
2_large_2 5 ms 5120 KB
3_prime_1 5 ms 5120 KB
3_prime_10 5 ms 5120 KB
3_prime_11 5 ms 5120 KB
3_prime_12 5 ms 5120 KB
3_prime_13 5 ms 5120 KB
3_prime_14 5 ms 5120 KB
3_prime_15 5 ms 5120 KB
3_prime_16 5 ms 5120 KB
3_prime_17 5 ms 5120 KB
3_prime_18 5 ms 5120 KB
3_prime_19 5 ms 5120 KB
3_prime_2 5 ms 5120 KB
3_prime_20 5 ms 5120 KB
3_prime_21 5 ms 5120 KB
3_prime_22 5 ms 5120 KB
3_prime_3 5 ms 5120 KB
3_prime_4 5 ms 5120 KB
3_prime_5 5 ms 5120 KB
3_prime_6 5 ms 5120 KB
3_prime_7 5 ms 5120 KB
3_prime_8 5 ms 5120 KB
3_prime_9 5 ms 5120 KB
4_hand_1 5 ms 5120 KB
4_hand_2 5 ms 5120 KB
4_hand_3 5 ms 5120 KB
sample_01 5 ms 5120 KB
sample_02 5 ms 5120 KB
sample_03 5 ms 5120 KB