/**
* @Author Baker.chen
* @create 2020/8/29 20:13
*
* 分解质因数
*
* 思路:
* 1. 首先设置一个变量k,k的值等于最小素数2,注意变量k应该声明为类成员变量,不能声明在方法中,否则多次递归调用方***导致栈内存溢出
* 2. 如果质数恰好等于n,代表分解已结束
* 3. 若n>k,但n能被k整除,先打印k值,并用n除以k的商作为新的n,然后递归执行
* 4. 若n不能被k整除,则用k+1作为k的值,然后递归执行
*/publicclassMain{privatestaticint k =2;publicstaticvoidmain(String[] args){
Scanner sc =newScanner(System.in);int n = sc.nextInt();f(n);}publicstaticvoidf(int n){while(k <= n){if(k == n){
System.out.print(n);break;}elseif(n > k && n % k ==0){
System.out.print(k +"*");
n = n / k;f(n);break;}elseif(n > k && n % k !=0){
k = k +1;f(n);break;}}}}
定义一个n*m的数字矩阵,找出不同行不同列的两个数的乘积的最大值
publicstaticvoidmain(String[] args){
Scanner scanner =newScanner(System.in);int n = scanner.nextInt();int m = scanner.nextInt();long[][] arr =newlong[n][m];for(int i =0; i < n; i++){for(int j =0; j < m; j++){
arr[i][j]= scanner.nextLong();}}long max =0;for(int i =0; i < n; i++){for(int j =0; j < m; j++){long one = arr[i][j];for(int k =0; k < n; k++){for(int z =0; z < m; z++){if(k != i && z != j){long two = arr[k][z];
max = Math.max(one * two, max);}}}}}
System.out.println(max);}