Bzoj 2257 JSOI2009 Bottle and fuel number theory

Source: Internet
Author: User

The main topic: given n bottles, choose K, you can guide the oil casually, asked to choose K bottles can be exported to the minimum value of the maximum number of oil

First of all, K bottles can be exported to the minimum oil must be K bottle capacity of the largest common factor so the problem is converted to the n number of the choice K to maximize the maximum common factor

Find out all the factor of n number to sort out the largest and the output with the number of occurrences greater than or equal to K

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 1600100using namespace Std;int n,k;int factors[m],tot;void get_factors (int x) {int i;for (i=1;i*i<x;i++) if (x%i==0) Factors[++tot]=i,factors[++tot]=x/i;if (i*i==x) factors[++tot]=i;} int main () {int i,x;cin>>n>>k;for (i=1;i<=n;i++) {scanf ("%d", &x); Get_factors (x);} Sort (factors+1,factors+tot+1); int cnt=0;for (i=tot;i;i--) {if (factors[i]!=factors[i+1]) cnt=0;++cnt;if (cnt==k) { printf ("%d\n", Factors[i]); return 0;}}}


Bzoj 2257 JSOI2009 Bottle and fuel number theory

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.