File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Explanations/Explanations 23 Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments