HDU 2709 Max Factor (素数因子)
来源:互联网 发布:二进制安装mysql详解 编辑:程序博客网 时间:2024/06/05 03:11
Max Factor
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8635 Accepted Submission(s): 2817
Problem Description
To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as better than others. In particular, a cow whose serial number has the highest prime factor enjoys the highest social standing among all the other cows.
(Recall that a prime number is just a number that has no divisors except for 1 and itself. The number 7 is prime while the number 6, being divisible by 2 and 3, is not).
Given a set of N (1 <= N <= 5,000) serial numbers in the range 1..20,000, determine the one that has the largest prime factor.
(Recall that a prime number is just a number that has no divisors except for 1 and itself. The number 7 is prime while the number 6, being divisible by 2 and 3, is not).
Given a set of N (1 <= N <= 5,000) serial numbers in the range 1..20,000, determine the one that has the largest prime factor.
Input
* Line 1: A single integer, N
* Lines 2..N+1: The serial numbers to be tested, one per line
* Lines 2..N+1: The serial numbers to be tested, one per line
Output
* Line 1: The integer with the largest prime factor. If there are more than one, output the one that appears earliest in the input file.
Sample Input
436384042
Sample Output
38
Source
USACO 2005 October Bronze
123
题目大意: 给你n个数, 问你这个n个数里的有 最大的质因子事那个;
既是因子, 又得是质因数
先素数达标,然后判断, 找最大的质因子;
#include <iostream>#include <stdio.h>#include <queue>#include <cmath>#include <cstring>#include <string>#include <map>#include <algorithm>int T;typedef long long ll;const int MAXN=20010;using namespace std;int k;int pre[MAXN];int num[MAXN];int s[MAXN];int ans[MAXN];void tab(){ k=1; pre[1]=1; for(int i=2;i<=MAXN;i++) { if(!pre[i]) { num[k++]=i; for(int j=i+i;j<=MAXN;j+=i) pre[j]=1; } }}int main(){ int n; tab(); while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) scanf("%d",s+i); for(int i=1;i<=n;i++) { if(!pre[s[i]])// 自己是素数 { ans[i]=s[i]; continue; } ans[i]=1; for(int j=1;num[j]<=s[i];j++) { if(s[i]%num[j]==0) //是因子,并且另一边是素数; { if(!pre[s[i]/num[j]])// 对应的 为素数 { if(num[j]>ans[i]) ans[i]=s[i]/num[j]; } } } } int mmax=ans[1]; int low=1; for(int i=1;i<=n;i++) { if(ans[i]>mmax) { mmax=ans[i]; low=i; } } printf("%d\n",s[low]); } return 0;}
阅读全文
0 0
- HDU 2709 Max Factor (素数因子)
- HDU 2710 Max Factor(素数筛选)
- HDU 2710 Max Factor 素数先打表
- 【HDU 2710】【素数筛选】Max Factor
- HDU 2710 Max Factor (素数筛选)
- HDU Largest prime factor && nyoj 520 最大素因子【素数】
- hdu 2710 Max Factor(找最大素数)
- HDU 2710 Max Factor (筛选求素数)
- HDOJ/HDU 2710 Max Factor(素数快速筛选~)
- HDU 2710 ( Max Factor )
- HDU 2710 Max Factor
- hdu 2710 Max Factor
- hdu (2710) Max Factor
- hdu 2710 Max Factor
- HDU 2710 Max Factor
- hdu 2710 Max Factor
- hdu 2710 Max Factor
- hdu 2710 Max Factor
- 深度学习笔记——TensorFlow学习笔记(三)使用TensorFlow实现的神经网络进行MNIST手写体数字识别
- iOS CoreAnimation(二)contentsRect,contentsCenter
- java并发编程-1.3线程的简单中断
- 图的遍历
- 第一章 第一个spring boot程序
- HDU 2709 Max Factor (素数因子)
- 【学习大作战】PopupWindow菜单实战
- [leetcode]: 225. Implement Stack using Queues
- 图解http
- Django学习
- MySQL主从复制
- MSSQL:用openrowset增改查xlsx
- 深度神经网络(Deep Neural Network, DNN)
- Mysql外部导入SQL文件