Bzoj 2257 [Jsoi2009] bottles and fuel

Source: Internet
Author: User
Tags gcd

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

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.