Skip to content

Commit 398490c

Browse files
Add files via upload
1 parent e6e84db commit 398490c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Let us notice that if N is a prime number we can't break it down further and can only assign it to one of k places.
2+
3+
------------------------
4+
5+
If N = p^m,
6+
7+
Then it is equal to the number of ways of writing m as the result of m summands.
8+
9+
This is like stars and bars.
10+
11+
The answer is C(m + k - 1, k - 1)
12+
13+
----------------------------------
14+
15+
Each prime is independent.
16+
17+
We will break down N into it's prime factors and solve seperately for each prime exponent.
18+
19+
--------------------------------
20+
21+
int main()
22+
{
23+
sieve();
24+
precompute();
25+
26+
int no_of_elements;
27+
cin >> no_of_elements;
28+
29+
map <int, int> prime_exponents;
30+
31+
for(int i = 1; i <= no_of_elements; i++)
32+
{
33+
int element;
34+
cin >> element;
35+
36+
factorise(element, prime_exponents);
37+
}
38+
39+
const int MOD = 1e9 + 7;
40+
long long answer = 1;
41+
for(map <int, int> :: iterator it = prime_exponents.begin(); it != prime_exponents.end(); it++)
42+
{
43+
int exponent = it->second;
44+
45+
answer *= choose(no_of_elements + exponent - 1, no_of_elements - 1);
46+
47+
answer %= MOD;
48+
}
49+
50+
cout << answer;
51+
return 0;
52+
}

0 commit comments

Comments
 (0)