HDU 5428 the Factor

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.