Max Factor hdu2710 素数相关

http://acm.hdu.edu.cn/showproblem.php?pid=2710

按最大质因数排序,输出含有最大质因数的数。

比较简单的问题啦。 =w=

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 20005
int factor[N];

void init(){
	int k=floor(sqrt((double)N)+0.5),i,j;
	for (i=0;i<N;i++)
		factor[i]=1;
	for (i=2;i<=k;i++){
		if (factor[i]==1)
			for (j=2;i*j<=N;j++)
				factor[i*j]=i;
	}
}

int max(int a,int b){
	if (a>=b)
		return a;
	return b;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("2710in.txt","r",stdin);
#endif
	int n,t,fac,m,mt;
	init();
	while (scanf("%d",&n)!=EOF){
		m=0;
		mt=0;
		while(n--){
			scanf("%d",&t);
			if (factor[t/factor[t]]==1)
				fac=max(factor[t],t/factor[t]);
			else fac=factor[t];
			if (fac>m){
				m=fac;
				mt=t;
			}
		}
		printf("%d\n",mt);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值