BZOJ2257: [Jsoi2009] bottles and fuel

Source: Internet
Author: User
Tags greatest common divisor

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

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.