Number Sequence
Time Limit: 10000/3000 MS (Java/others) memory limit: 65536/65536 K (Java/Others)Total submission (s): 790 accepted submission (s): 331
Problem descriptiongiven a number sequence b1, b2... Bn.
Please count how many numbers sequences A1, A2,..., an satisfy the condition that A1 * A2 *... * an = b1 * B2 *... * Bn (AI> 1 ).
Inputthe input consists of multiple test cases.
For each test case, the first line contains an integer N (1 <= n <= 20 ). the second line contains N integers which indicate b1, b2 ,..., BN (1 <Bi <= 1000000, B1 * B2 *... * Bn <= 1025 ).
Outputfor each test case, please print the answer module 1e9 + 7.
Sample Input
23 4
Sample output
4HintFor the sample input, P=3*4=12.Here are the number sequences that satisfy the condition:2 63 44 36 2
Source2012 multi-university training contest 10:
Evaluate a series of A1, A2,... an, so that a 1 * A 2 *... * A n = B 1 * B 2 *... * B n, where AI> 1;
Ideas:
I had no idea at the beginning. I searched for it online for a long time and found that many blogs are the same. I summarized it later ..
1. First, use map to store the number of occurrences of each factor for each bi and sister. At this time, the quality factor of ai * A2 *... An is saved by map;
2. now the problem is to put n identical numbers into M boxes. If the box can be empty, all the cases are C (m-1, n-1). Then, calculate the number of factors saved in the map one by one,
Then, we can use the multiplication principle to find all the situations when the box can be empty.
3. The question requires that the box cannot be empty, which requires mathematical induction:
F [I]-number of input types that can be empty, G [I]-number of input types that cannot be empty:
F [1] = G [1]
F [2] = G [2] + C (2, 1) * g [1],
F [3] = G [3] + C (3,1) * g [2] + C (3,2) * g [1],
......
G [N] = f [N]-C (n, 1) * f [n-1] + C (n, 2) * f [N-2]-...
Calculate the number of groups with I boxes empty in sequence, and apply the principle of rejection: -G [1] + G [2]-G [3] + G [4] ......;
My code:
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <string> # include <algorithm> # include <cstdlib> # include <set> # include <queue> # include <stack> # include <vector> # include <map> # define n 100010 # define mod 1000000007 # define lson l, mid, idx <1 # define rson Mid + 1, R, idx <1 | 1 # define LC idx <1 # define RC idx <1 | 1 const double EPS = 1e-11; const double Pi = ACOs (-1.0 ); const Double E = 2.718281828; ty Pedef long ll; const int INF = 1000010; using namespace STD; int C [1001] [45]; // map the number of combinations <int, int> MP; void Init () {for (INT I = 0; I <= 1000; I ++) C [I] [0] = 1; /// select 1 for 0 I; for (INT I = 1; I <= 1000; I ++) for (Int J = 1; j <= 42; j ++) C [I] [J] = (C [I-1] [J] + C [I-1] [J-1]) % MOD; // C (n, k) = C (n-1, k) + C (n-1, k-1), can prove by yourself} void fenjie (int n) // decomposition prime factor {for (INT I = 2; I * I <= N; I ++) {If (N % I = 0) {While (N % I = 0) {MP [I] ++; n/= I ;}} if (n = 1) Br Eak;} If (n> 1) MP [N] ++;} int main () {Init (); int N; while (CIN> N) {MP. clear (); int B; For (INT I = 0; I <n; I ++) {scanf ("% d", & B); fenjie (B );} ll ans = 0; For (INT I = 0; I <n; I ++) // The principle of rejection {ll TEM = C [N] [I]; map <int, int>: iterator it; for (IT = MP. begin (); it! = MP. end (); It ++) // calculate the number of groups with I boxes empty {int T = it-> second + n-i-1; TEM * = C [T] [n-i-1]; TEM % = MOD;} if (I % 2) ans-= TEM, ANS + = MOD; else ans + = TEM; ans % = MOD;} cout <ans % mod <Endl;} return 0 ;}
HDU 4390 Number Sequence)