1616 Minimum set 51NOD (get along with greatest common divisor +stl)

Source: Internet
Author: User
Tags gcd greatest common divisor

1616 minimum set base time limit: 1 seconds space limit: 131072 KB score: 80 Difficulty: 5-level algorithm topic collection attention

A June has a collection.

This set has a magical nature.

If x, y belongs to the collection, then the largest common factor of x and y also belong to that collection.

But he forgot what numbers were in the collection.

Fortunately, he remembered the n numbers.

Of course, perhaps because of excessive tension, the number he remembered may be repeated.

He wants to restore the original collection.

He knew it was impossible ...

What he wants to know now is that there are at least a few in the original set.


Sample explanation:

There must be {1,2,3,4,6} in the collection

Input
The first row is a number n (1<=n<=100000). Second row n number, AI (1<=ai<=1000000,1<=i<=n). The number that a June remembered. The number entered may be duplicated.
Output
The output line indicates how many different numbers exist at least.
Input example
51 3 4) 6 6
Output example
5
#include <iostream>#include<cstdio>#include<cstring>#include<Set>using namespacestd;Set<int>se;intN;intb[10000],ans;intgcdintXinty) {    returnx = =0? Y:GCD (y%x, x);}intMain () {CIN>>N;  for(inti =0; I < n; i++) {cin>>B[i];    Se.insert (B[i]); }     for(inti =0; I < n; i++){         for(intj = i+1; J < N; J + +) {Se.insert (GCD (B[i], b[j])); }} cout<<se.size ();}

Idea: Enter number B, stored with the set set in the STL, because the set set does not contain the same elements, so it implements the de-weight;

Then 22 compare to find GCD, into the set SE, the length of the last SE is the number of stored numbers;

Title Address: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1616

1616 Minimum set 51NOD (get along with greatest common divisor +stl)

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.