2257: [Jsoi2009] bottle and fuel time limit:10 Sec Memory limit:128 MB Description
Jyy has been thinking of returning to Earth as soon as possible, but his ship's fuel is not enough.
One day he went to the Martians to fuel, this time the Martians promised to jyy with the ship's bottles to change. Jyy
On the ship there are N bottles (1<=n<=1000), after consultation, the Martians as long as the K. Jyy
After handing K bottles to the Martians, the Martians used them to put some fuel into the jyy. All the bottles have no scale, only
The volume is marked at the bottle, and the volume of the I Bottle is VI (vi is an integer and satisfies the 1<=vi<=1000000000).
Martians are stingy, and they are not going to fill all the bottles with fuel. When they get the bottle, they run to the fuel.
The library tinker with a little bit of fuel to get it over with. Jyy, of course, knew they would come to this, so they knew the fire beforehand.
The specific contents of the Star-man Tinker. Martians in the fuel depot will only do the following 3 operations: 1, a bottle filled with fuel;
2. Pour all the fuel in a bottle back into the fuel bank, 3. Pour the fuel from bottle A to bottle B until the bottle B is full.
Or bottle A is empty. Losses in the process of fuel dumping can be neglected. The Martians are taking out the fuel, of course, that these operations can
The smallest positive volume obtained.
Jyy knows that for different bottle combinations, Martians may be forced to give different volumes of fuel. Jyy hope to find
To the optimal bottle mix, allowing the Martians to give as much fuel as they could.
Input
Line 1th: 2 integers n,k,
2nd.. N rows: 1 integers per line, and the integer for line i+1 is VI
Output
Only 1 lines, an integer, represents the maximum value of the fuel given by the Martians.
Sample Input3 2
3
4
4Sample Output4
HINT
By choosing the 2nd bottle and the first bottle, the Martians were forced to give 4 volumes.
Source
TIP:
In fact, the title can be converted to the number of K extracted from N
So that the number of K greatest common divisor the largest;
Because each number is less than 1e+09, contains a number of numbers will not exceed 1w;
Put all the factors together to find the maximum factor (greater than or equal to K);
Code:
#include <cstdio>#include<algorithm>#include<cstring>#include<iostream>using namespacestd;intn,m,x,f[10000008],tot;inlineintRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} while(ch>='0'&&ch<='9') {x= (x<<3) + (x<<1) +ch-'0'; Ch=GetChar ();} returnx*F;}voidAddintxx) { for(intI=1; i*i<=xx;i++) if(xx%i==0) {f[++tot]=i; if(i!=xx/i) f[++tot]=xx/i; }}intMain () {n=read (); m=read (); for(intI=1; i<=n;i++) {x=read (); Add (x); } sort (F+1, f+tot+1); intnum=1; for(inti=tot;i>=1; i--){ if(f[i]==f[i+1]) num++;Elsenum=1; if(num>=L) {printf ("%d", F[i]); return 0; } }}
bzoj2257: [Jsoi2009] bottles and fuel