Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined), problem: (B) Bash’s Big Day Solution in C/C++

#include <stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	int i, temp, max=1, freq[100001]={0}, ans=1, j;
	for(i=0;i<n;i++){
		scanf("%d",&temp);
		freq[temp]++;
		if(temp>max){
			max=temp;
		}
	}
	for(i=2; i<=max; ++i){
		temp=0;
		for(j=i; j<=max; j+=i){
			temp+=freq[j];
		}
		if(temp>ans) ans=temp;
	}
	printf("%d",ans);
	return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *