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)