参考代码:
import java.lang.annotation.Retention; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class 因式分解 { /** * @param args */ static ArrayList<Integer> arrayList = new ArrayList<Integer>(); public static void main(String[] args) { // TODO Auto-generated method stub //1903: [蓝桥杯][算法提高VIP]因式分解 Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(); // 求因数 for (int s = 2; s <= a; s++) { if (a % s == 0) { int j = 2; int k = (int) Math.sqrt(s);// i的平方根 for (j = 2; j <= k; j++) { if (a % j == 0) {// i:11 break; } } if (j > k) { arrayList.add(s); } } } int v = 1; for (Integer l : arrayList) { v *= l; } while (H(a, v)==1) { v = 1; for (Integer l : arrayList) { v *= l; } } Collections.sort(arrayList); int w=0; for (Integer z : arrayList) { w++; if (arrayList.size()==w) { System.out.println(z); }else { System.out.print(z+"*"); } } } public static int H(int n, int m) { int num = n / m; for (int s = 2; s <= num; s++) { if (num % s == 0) { int j = 2; int k = (int) Math.sqrt(s);// i的平方根 for (j = 2; j <= k; j++) { if (s % j == 0) {// i:11 break; } } if (j > k) { arrayList.add(s); return 1; } } } return 0; } }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:600 |
破解简单密码 (C语言代码)浏览:1758 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:632 |
简单的a+b (C语言代码)浏览:547 |
A+B for Input-Output Practice (V) (C++代码)浏览:450 |
字符串对比 (C语言代码)浏览:1398 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:850 |
妹子杀手的故事 (C语言代码)浏览:1216 |
【简单计算】 (C语言代码)浏览:622 |
WU-输入输出格式练习 (C++代码)浏览:1076 |