1. Title Description: Click to open the link
2. Thinking: Through the test can be found that the problem is equivalent to solving C (n-1,i) in the combination of the number of M is a multiple, you can use the unique decomposition theorem to judge: pre-decomposition M, and then use recursion to calculate each item contains m of the exponent of the factor.
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std; #define N 100005int fac[100][2];//a table, FAC[I][0] Storage factor, fac[i][1] store its exponent int fac_c[100];int a[n];void factor (int m)//Decomposition M{int&num = fac[0][0];//fac[0][0] is the table header, The total number of stores, using the reference is more convenient num = 0;for (int i = 2; i*i <= m;i++) if (m%i = = 0) {Fac[++num][0] = i;fac[num][1] = 0;do{fac[num][1]++;m/ = i;} while (m%i = = 0);//Will I except clean}if (M > 1)//If decomposition to the last m is still greater than 1, indicating that it is a prime number. Note: If you just judge what the element factor is, you can not judge it here, otherwise you must have this step {fac[++num][0] = m;fac[num][1] = 1;}} BOOL Check (int n, int j)//According to the recursive formula to calculate the J term, check the unique decomposition of the exponent {int num = Fac[0][0];int A = n-j;//is actually ((n-1) +j+1) after simplifying the result of int b = J;for (i NT i = 1; I <= num; i++) {int p = Fac[i][0];int&q = fAc_c[i];for (; a%p = = 0; a/= p, q++);//In order to improve efficiency, only the factor in the decomposition formula of M is used for (; b%p = 0; b/= p, q--);} for (int i = 1; I <= num;i++) if (fac[i][1] > Fac_c[i]) return False;return true; int main () {//freopen ("test.txt", "R", stdin), int n, m;while (CIN >> n >> m) {int cnt = 0;factor (m); Memset (Fac_c , 0, sizeof (fac_c)), for (int i = 1; i < n;i++)//Direct Check 1 to n-1 (starting from 0) if (check (n, i)) a[cnt++] = i + 1;printf ("%d\n", CNT); fo R (int i = 0; i < cnt; i++) printf ("%s%d", i = = 0?) "": "", A[i]);p rintf ("\ n");} return 0;}
Example 10-6 unrelated elements UVa1635