问题描述
给出N个数字,求出有最大的最大质因数的那个数
输入格式
第一行:一个整数N。
接下来的N行,每行一个整数A_i,表示给出的那N个数字。
输出格式
第一行:一个整数,拥有最大的最大质因数的那个数。
样例输入
4
36
38
40
42
样例输出
38
数据规模和约定
60%的数据满足:N<=100
100%的数据满足:N<=2500,A_i<=20000
错误的,只有40分。为什么呢?
package 数学;
import java.util.Arrays;
import java.util.Scanner;
public class 最大质因数 {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();//输入一个整数n
int[] a=new int[n];
int[] b=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
b[i]=GetMaxPrime(a[i]);
}
//如何输出最大的数字
int temp=b[0];
int ss=0;
for(int i=1;i<n-1;i++){
if(temp<=b[i]){
temp=b[i];
ss++;
}
}
System.out.println(a[ss]);
}
public static int GetMaxPrime(int n){
int i=2;
int res=1;
while(n>2){
if(n%i==0){
n/=i;
res=i;
}else
i++;
}
return res;
}
}