51nod 1179 the largest greatest common divisor

Source: Internet
Author: User
Tags greatest common divisor

1179 the largest greatest common divisortitle Source: SGUbase time limit: 1 seconds space limit: 131072 KB Score: 40 Difficulty: 4-level algorithm problemgive n positive integers to find the maximum value of greatest common divisor between n number 22. For example: N = 4, 4 numbers: 9 15 25 16, 22 the maximum value between greatest common divisor is 15 with 25 greatest common divisor 5.  Input
Line 1th: A number n, which represents the number of input positive integers. (2 <= N <= 50000) 2-n + 1 lines: 1 numbers per line, corresponding positive integers for input. (1 <= s[i] <= 1000000)
Output
The maximum value of greatest common divisor between output 22.
Input Example
49152516
Output Example
5

/*51nod 1179 the largest greatest common divisor gives you the number of n, ask them the maximum number of conventions between 22 to find all the n number of factors and record the number of occurrences, and then find the NUM >= 2 (two numbers have this factor) the maximum value can be HHH-2016/05/26 21:57*/#include <iostream> #include <vector> #include <cstring> #include <string> #include < cstdio> #include <queue> #include <cmath> #include <algorithm> #include <functional># Include <map>using namespace std; #define Lson (i<<1) #define Rson ((i<<1) | |) typedef LONG LONG ll;using  namespace Std;const ll maxn = 1000010;const double PI = 3.1415926;const double eps = 1e-15;int n;int num[maxn];int ans;int    Main () {//freopen ("In.txt", "R", stdin);    int n,x;    scanf ("%d", &n);    int Max = 0;        for (int t = 0;t < n;t++) {scanf ("%d", &x);        max = max (X,max);        num[1]++;        num[x]++;                for (int i = 2; i*i <= x; i++) if (x%i = = 0) {num[i]++;            num[x/i]++; }} for (int i = Max;i >= 1;i--) {if (Num[i] >= 2) {ans = i;        Break    }} printf ("%d\n", ans); return 0;}

  

51nod 1179 the largest greatest common divisor

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.