7

@依然菜刀 你好，想跟你请教个问题：

72=2^3*3^2

181944=2^3*3^2*7*19^2

package test;

import java.util.ArrayList;

public class Rotating {

public static ArrayList<Integer> getNumber(int n) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 2; i < n; i++) {
int sum = 1;

for (int j = 1; j <= i; j++) {
if (i % j == 0) {
sum *= j;
}
}
if (sum == i) {
}
}
return list;
}

public static ArrayList<Integer> getChildNumber(int number) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 1; i < number; i++) {
if (number % i == 0) {
}
}
return list;
}

public static ArrayList<Integer> getPrimeNumber(ArrayList<Integer> list, ArrayList<Integer> al) {
ArrayList<Integer> arr = new ArrayList<Integer>();
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < al.size(); j++) {
for (int j2 = 0; j2 < j; j2++) {
if (Math.pow(al.get(j), al.get(j2)) == list.get(i)) {
if (!arr.contains(al.get(j))) {
}
if (!arr.contains(al.get(j2))) {
}
}
}
}
}
return arr;
}

public static void main(String[] args) {
int n = 181944;
ArrayList<Integer> al = Rotating.getNumber(n);
//        System.out.println(al);

ArrayList<Integer> list = Rotating.getChildNumber(n);
//        System.out.println(list);

ArrayList<Integer> arr = new ArrayList<Integer>();

System.out.println(arr);
}
}

<无标签>

lzhphantom

``````import java.util.*;
public class ZhiShu1
{
void zhuanhuan(long g)
{
for(long i=2;g!=1;i++)
if( g%i==0 ) {
g /= i;
System.out.printf(" %d",i);
i--; /*i--使得i的值不变,即能把含有的所有的当前质因数， 如 2，
除尽后， 再去除下一个指数， 如 3*/
}
System.out.println();
}
}
class Zhu
{
public static void main (String[] args)
{
System.out.println("Integer.MAX_VALUE:" + Integer.MAX_VALUE);
System.out.println("Long.MAX_VALUE:" + Long.MAX_VALUE);
Scanner out = new Scanner(System.in);
System.out.println("输入一个 long 型数据, 即 不大于 9223372036854775807：");
long zhengshu= out.nextLong();
System.out.println( zhengshu + " 的质因数是：" );
ZhiShu1 t1;
t1 = new ZhiShu1();
t1.zhuanhuan(zhengshu);

}
}``````

--- 共有 1 条评论 ---
lzhphantom多谢大佬，新思路，已收下 11个月前

package com;

public class Test {

public static void test(int num){
for(int i = 2;i < num;i++){
if(checkNum(i) && (num % i == 0)){
System.out.println(i);
test(num/i);
return;
}
}
System.out.println(num);
}
public static boolean checkNum(int num){
for(int i = 2;i < num;i++){
if(num % i == 0){
return false;
}
}
return true;
}
public static void main(String[] args) {
Test.test(181944);
}
}

--- 共有 2 条评论 ---

tcxu代码没错！ 但注意一点， 由于程序是通过 int 类型计算的，所测试的参数，不能超过最大的正整数： Integer.MAX_VALUE:2147483647 11个月前

--- 共有 1 条评论 ---
lzhphantomwrite a program that input a positive integer, find out all the prime factors of it. the prime factors of 72 is 2,3 Example 72 =2^3* 3^2 181944 =2^3 *3^2*7*19^2 the prime factors of181944 is 2,3,7,19 11个月前
write a program that input a positive integer, find out all the prime factors of it. the prime factors of 72 is 2,3 Example 72 =2^3* 3^2 181944 =2^3 *3^2*7*19^2 the prime factors of181944 is 2,3,7,19