Exercises
The bezout theorem needs to be used.
The minimum amount of fuel that a k bottle can pour out is the gcd of the capacity of the K-bottle. Then the original problem is converted to find the number of K in the N number so that their gcd maximum. Because the range of n is very small, all factors are calculated for each number and sorted, and the last factor that is greater than or equal to K is the answer.
#include <cstdio> #include <algorithm> #include <cmath> #define N 1000010#define RG registerusing namespace Std;int n,k,a[n],tot,now,cnt;inline int read () {int k=0,f=1; char C=getchar (); while (c< ' 0 ' | | C> ' 9 ') c== '-' && (f=-1), C=getchar (); while (' 0 ' <=c&&c<= ' 9 ') k=k*10+c-' 0 ', C=getchar (); return K*f;} inline BOOL cmp (int x,int y) {return x>y;} int main () {n=read (); K=read (); for (RG int i=1;i<=n;i++) {int x=read (), for (RG int j=1;j<=sqrt (x); j + +) if (! ( X%J) {a[++tot]=j;if (j!=x/j) a[++tot]=x/j;}} Sort (a+1,a+1+tot,cmp), for (RG int i=1;i<=tot;i++) {if (Now!=a[i]) now=a[i],cnt=1;else cnt++;if (cnt>=k) {printf (" %d\n ", A[i]); return 0;}} return 0;}
Bzoj 2257 [Jsoi2009] bottles and fuel