标签:ar sp for java 代码 ad html amp as
import java.util.*; class 分解质因数 { static ArrayList<Integer> al; public static void main(String[] args) { al=new ArrayList<Integer>(); fenjie(84729332); System.out.println(al); } public static void fenjie(int x) { if(isPrime(x)) { al.add(x); return; } if(x%2==0) { al.add(2); x=x/2; fenjie(x); return; } for(int i=3;i<x;i++) if(x%i==0 && isPrime(i)) { al.add(i); x=x/i; fenjie(x); } } public static boolean isPrime(int n) { if(n==2) return true; if(n%2==0 )//|| n<ts.last()) return false; for(int i=3;i<n;i+=2) if(n%i==0) return false; return true; } }
标签:ar sp for java 代码 ad html amp as
原文地址:http://blog.csdn.net/ylqhust/article/details/41910067