ACdream OJ 1153 (k-GCD)

Source: Internet
Author: User

ACdream OJ 1153 (k-GCD)

 

Question:

Obtain the number of k from the given number of n, so that their maximum number of public approx is the largest, and calculate the maximum number of public approx.

 

Analysis:

Brute-force decomposition is not desirable. We can obtain the maximum number of common orders between [1, mmax] (mmax is the largest element). Because mmax is not large,

Therefore, we can enumerate the approximate number from large to small, and then calculate whether the number of its multiples is greater than or equal to k. If so, this number must be the largest.

 

The Code is as follows:

 

#include 
 
  #include 
  
   #include 
   
    using namespace std;const int maxn = 10010;int a[maxn];int main(){    int n,k,t,x;    scanf(%d,&t);    while(t--){        scanf(%d%d,&n,&k);        memset(a,0,sizeof(a));        int mmax = 0;        for(int i=0;i
    
      mmax) mmax = x;        }        int ans;        bool f=0;        for(int i=mmax;i>=1;i--){            int cnt=0;            for(int j=i;j<=mmax;j+=i){                cnt += a[j];                if(cnt>=k){                    ans = i;                    f=1;                    break;                }            }            if(f) break;        }        printf(%d,ans);    }    return 0;}
    
   
  
 


 

 

Related Article

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.