[Introduction to programming in Java 笔记] 1.3.9 Factoring integers 素因子分解
素数 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 素因子分解的更多相关文章
- [Introduction to programming in Java 笔记] 1.3.8 Gambler's ruin simulation 赌徒破产模拟
赌徒赢得机会有多大? public class Gambler { public static void main(String[] args) { // Run T experiments that ...
- [Introduction to programming in Java 笔记] 1.3.7 Converting to binary 十进制到二进制的转换
public class Binary { public static void main(String[] args) { // Print binary representation of N. ...
- Thinking in Java——笔记(1)
Introduction To Obejct The progress of abstraction But their primary abstraction still requires you ...
- java笔记整理
Java 笔记整理 包含内容 Unix Java 基础, 数据库(Oracle jdbc Hibernate pl/sql), web, JSP, Struts, Ajax Spring, E ...
- Effective Java笔记一 创建和销毁对象
Effective Java笔记一 创建和销毁对象 第1条 考虑用静态工厂方法代替构造器 第2条 遇到多个构造器参数时要考虑用构建器 第3条 用私有构造器或者枚举类型强化Singleton属性 第4条 ...
- java笔记00-目录
--2013年7月26日17:49:59 学习java已久,趁最近有空,写一个总结: java笔记01-反射:
- 每天一本电子书 - JavaScript for Kids: A Playful Introduction to Programming
JavaScript for Kids: A Playful Introduction to Programming 作者: Nick Morgan 出版社: No Starch Press 副标题 ...
- 2018-12-09 疑似bug_中文代码示例之Programming in Scala笔记第九十章
续前文: 中文代码示例之Programming in Scala笔记第七八章 源文档库: program-in-chinese/Programming_in_Scala_study_notes_zh ...
- 2018-11-27 中文代码示例之Programming in Scala笔记第七八章
续前文: 中文代码示例之Programming in Scala学习笔记第二三章 中文代码示例之Programming in Scala笔记第四五六章. 同样仅节选有意思的例程部分作演示之用. 源文档 ...
随机推荐
- 是否存在两个树的和是固定数 hashmap使用 leecode
two sum https://oj.leetcode.com/submissions/detail/8220548/ public class Solution { public int[] two ...
- Arrays.sort源代码解析
Java Arrays.sort源代码解析 Java Arrays中提供了对所有类型的排序.其中主要分为Primitive(8种基本类型)和Object两大类. 基本类型:采用调优的快速排序: 对象类 ...
- linux IPC总结——管道
管道 管道是unix ipc的最古老形式,是一种在内存中的特殊文件,只能在具有公共祖先的进程之间使用(即父子进程,兄弟进程). 管道由pipe函数创建 #include <unistd.h> ...
- ZOJ Problem Set - 1025解题报告
ZOJ Problem Set - 1025 题目分类:基础题 原题地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=10 ...
- 【转】tmux入门指南
按照官方说明,tmux是一个终端复用软件.我接触tmux也就是这几天的事情,但已经发现其强大.作为一个文艺程序员,有必要向大家分享一下,这么好的东东怎敢藏着掖着. 先用起来再说 假设你已经装好tmux ...
- flashback drop(2015-2-3学习日记)
知识面是由知识点组成的,你在研究某一个知识点的时候常常会遇到另一个知识点,然后你去研究那个知识点,又会带出更多的知识点,最终组成了知识面. 今天在看书的时候看到一个删除表的语句: DROP TABLE ...
- SecureCRT 无法删除字符
1. 2.
- 【转】android的startActivityForResult学习心得
http://blog.csdn.net/yanzi1225627/article/details/7800529 从昨晚到现在终于调试通了一个startActivityForResult的例子,网上 ...
- [TypeScript] Reflection and Decorator Metadata
TypeScript allows you to emit decorator metadata which enables more powerful features through reflec ...
- mysql_convert_table_format 批量修改表引擎
[root@server-mysql bin]# mysql_convert_table_format --help Conversion of a MySQL tables to other sto ...