[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笔记第四五六章. 同样仅节选有意思的例程部分作演示之用. 源文档 ...
随机推荐
- Web---Cookie技术(显示用户上次登录的时间、显示用户最近浏览的若干个图片(按比例缩放))
本章博客讲解: 1.Cookie基本用法演示 2.演示Cookie的访问权限 3.演示Cookie的删除 4.利用Cookie显示用户上次登录的时间 5.利用Cookie技术显示用户最近浏览的若干个图 ...
- Android核心基础(手机卫士的一个知识点总结)
注意:有些功能是需要权限的,在这里并没有写出来,在程序运行中,根据程序报的错误,添加相应的权限即可,里面的具体里面可能有一些小细节,没有明确的写出来,具体的需要在程序中自己调试,解决. 这个总结涵盖了 ...
- Bzoj 2834: 回家的路 dijkstra,堆优化,分层图,最短路
2834: 回家的路 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 62 Solved: 38[Submit][Status][Discuss] D ...
- [ZETCODE]wxWidgets教程一:介紹
本教程原文链接:http://zetcode.com/gui/wxwidgets/introduction/ 翻译:瓶哥 日期:2013年11月26日星期二 邮箱: 414236069@qq.com ...
- Hadoop--Map/Reduce实现多表链接
MR实现多表连接的原理和单表连接时一样的,甚至比单表连接还要简单. 在map阶段只需要根据文件的名称区分左表还是右表.使用关联的字段作为key2. 在reduce中对values中的值分别存储到一个左 ...
- JavaScript运行机制浅析
从一个简单的问题谈起: <script type="text/javascript"> alert(i); var i = 1; </script> 输出结 ...
- jsp 多条记录提交
前端jsp页面可以通过form提交标有name属性值得input的value数据给服务器,其中如何传递数组形式呢?如下: 1.前端jsp页面 其中灰色的部分是一个循环出现的值,因此form提交后,后台 ...
- DevExpress GridControl 后台设置列
/// <summary> /// 初始化GridView /// </summary> /// <param name="gv">GridVi ...
- 在VS Nuget命令行下进行EF数据库迁移
找到项目中,用到数据库DLL的地方,然后选中该项目,打开Nuget命令行输入以下的命令: 其中cardId为迁移名称,自己取
- 将文件的图标添加到LISTVIEW中
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...