码迷,mamicode.com
首页 > 编程语言 > 详细

[Introduction to programming in Java 笔记] 1.3.9 Factoring integers 素因子分解

时间:2016-02-20 00:28:29      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

素数 A prime is an integer greater than one whose only positive divisors are one and itself.
整数的素因子分解是乘积等于此素数的集合。
例如:3757208 = 2*2*2*7*13*13*397

public class Factors
{
    public static void main(String[] args)
    { // Print the prime factors of N. 
        long N = Long.parseLong(args[0]);
        long n = N;
        for (long i = 2; i <= n/i; i++)
        { // Cast out and print i factors
            while(n % i == 0)
            {
            n /= i;
            System.out.print(i + " ");
            // Any factors of n are greater than i.
            }
        } 
    if (n > 1) System.out.print(n);
    System.out.println();
    }
}

没看懂...









[Introduction to programming in Java 笔记] 1.3.9 Factoring integers 素因子分解

标签:

原文地址:http://www.cnblogs.com/learning-c/p/5202402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!