Main topic:
There are n numbers, and the number of K is selected to maximize the smallest positive integers that are obtained by adding and reducing the numbers.
Exercises
These numbers are the smallest number that can be obtained by the addition and subtraction of their greatest common divisor.
The topic requires n numbers to choose K to make their greatest common divisor the largest one.
Enumerate all the approximations to find the largest number of occurrences greater than K.
Code:
#include <cstdio> #include <algorithm> #include <cmath> using namespace Std;int cnt,a[1000005];void Find (int x) {for (int i=1; i<=sqrt (x); i++) if (x%i==0) {a[++cnt]=i;if (i!=x/i) a[++cnt]=x/i;}} int main () {int n,k;scanf ("%d%d", &n,&k), for (int i=1; i<=n; i++) {int x;scanf ("%d", &x); find (x);} Sort (a+1,a+cnt+1); int tmp=1;for (int i=cnt; i>0; i--) {if (a[i]==a[i+1]) tmp++;else{if (tmp>=k) {printf ("%d\n", a[i +1]); return 0;} Tmp=1;}} return 0;}
BZOJ2257: [Jsoi2009] bottles and fuel