To give n numbers in ascending order, you must find a substring. Each two adjacent numbers do not have mutual quality, and the length of the longest string is obtained.
Prompt
1) DP [I] indicates the longest string to the number I
2) DP [I] is updated with metric items that are not in the same quality as item I in the previous I-1
3) The search and I items do not have mutual quality, that is, the search and I items have a public factor, so the establishment of an array dig [I] indicates the number of times this factor appears
# Include <stdio. h> # include <string. h> # define maxn limit 5int DP [maxn]; int dig [maxn]; int mark [maxn]; int gcd (int A, int B) {int K; while (B! = 0) {k = A % B; A = B; B = K;} return a;} int max (int A, int B) {return a <B? B: A;} int find (int A) {int Maxx = 0; if (a = 1 | A = 2 | A = 3) {dig [a] ++; return 1 ;}int I = 0, j = 2; int flag = 1; while (J * j <=) {if (a % J = 0) {dig [J] ++; flag = 0; If (J * J! = A) Dig [A/J] ++; Maxx = max (Maxx, dig [J]), dig [A/J]);} J ++ ;} j = 2; while (J * j <= A) // update the number of occurrences of all the I-th factors to the maximum value !!! {If (a % J = 0) {dig [J] = Maxx; If (J * J! = A) Dig [A/J] = Maxx;} J ++;} If (flag = 1) // Dig [a] of prime numbers is directly added with 1 {dig [a] ++; return 1;} return Maxx;} void Init () {int I; for (I = 0; I <maxn; I ++) {mark [I] = 0; DP [I] = 0; Dig [I] = 0 ;}} int main () {int N; int I, j, k; int num [maxn]; int m; int tot; while (scanf ("% d", & N )! =-1) {Init (); M = 0; for (I = 1; I <= N; I ++) {scanf ("% d ", & num [I]); Mark [num [I] = I ;}for (I = 1; I <= N; I ++) {tot = find (Num [I]); DP [I] = tot; M = max (M, DP [I]);} printf ("% d \ n ", m);} return 0 ;}