Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200 points
Problem Statement
Given is an integer sequence A: A1,A2,A3,…,AN.Let the GCD-ness of a positive integer k be the number of elements among A1,A2,A3,…,AN that are divisible by k.Among the integers greater than or equal to 2, find the integer with the greatest GCD-ness. If there are multiple such integers, you may print any of them.
Constraints
- 1≤N≤100≤N≤100
- 2≤Ai≤1000
- All values in input are integers.
Input
Input is given from Standard Input in the following format: N A1A2A3…ANOutput
Print an integer with the greatest GCD-ness among the integers greater than or equal to 22. If there are multiple such integers, any of them will be accepted.
Sample Input 1
3 3 12 7Sample Output 1
3Among 3, 12, and 7, two of them - 3 and 12 - are divisible by 3, so the GCD-ness of 3 is 2.
No integer greater than or equal to 2 has greater GCD-ness, so 3 is a correct answer.
Sample Input 2
5 8 9 18 90 72Sample Output 2
9In this case, the GCD-ness of 9 is 4
2 and 3 also have the GCD-ness of 4, so you may also print 2 or 3.Sample Input 3
5 1000 1000 1000 1000 1000Sample Output 3
1000解题思路:拿到手,第一眼(没看题)看了输入的形式加上有个GCD我还以为要靠贝祖定理了呢,然后仔细分析是求一个K,K满足两个条件
①:K是输入的数组的元素的公因数,且从2开始。
②:k的倍数的数最多(当然这样的话就会有很多情况,随便输出一种情况就行)
再一看数据,这么小直接二重循环暴力出来啦,外层循环从2开始,一直到1000,内次循环遍历数组,每次内存循环记录满足倍数条件的个数
Code:
#include
#include
#include
#include
using namespace std;
int a[1005];
int main()
{
int n;
scanf("%d",&n);
for(int i = 1; i
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?


微信扫码登录