Test instructions: Give the number of N, ask the number of n the product of the smallest factor with at least three factors.
Solution: In addition to 1 and prime number of positive integers have at least three factors, so only the smallest of the product is not a non-prime factor of 1 can be, for each number decomposition of the mass factor, the smallest of all the quality factors of the product is the answer, if there is no two qualitative factors there is no answer. Note longlong! Note longlong! Note longlong! The important thing to say three times.
Code:
#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL Long longusing namespace Std;int cnt = 0;int prime[45000];void init () {bool isprime[45005] = {0}; for (int i = 2; I <= 45000; i++) {if (!isprime[i]) {prime[cnt++] = i; for (int j = i + i; j <= 45000; j + = i) isprime[j] = 1; }}}int Main () {init (); int T; while (~SCANF ("%d", &t)) {while (t--) {int n; int a[105]; Vector <int> v; scanf ("%d", &n); for (int i = 0; i < n; i++) {scanf ("%d", &a[i]); int j = 0; int x = A[i]; int flag= 0; for (j = 0; J < cnt && A[i] >= prime[j]; j + +) {while (A[i]% prime[j] = = 0) {V.push_back (prime[j]); flag = 1; A[i]/= prime[j]; }} if (!flag && x! = 1) v.push_back (x); } sort (V.begin (), V.end ()); for (int i = 0; i < v.size (); i++)//cout << v[i] << Endl; if (V.size () < 2) printf (" -1\n"); else printf ("%lld\n", (LL) v[0] * v[1]); }} return 0;}
HDU 5428 the Factor