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;}