UVA 10392 (13.07.28)
Problem F: Factoring Large Numbers
One of the central ideas behind much cryptography is that factoringlarge numbers is computationally intensive. In this context one mightuse a 100 digit number that was a product of two 50 digit primenumbers. Even with the fastest projected computers this factorizationwill take hundreds of years.
You don't have those computers available, but if you are clever youcan still factor fairly large numbers.
Input
The input will be a sequence of integer values, one per line,terminated by a negative number. The numbers will fit in gcc'slong long int
datatype.You may assume that there will beat most one factor more than 1000000.
Output
Each positive number from the input must be factored and all factors(other than 1) printed out. The factors must be printed in ascendingorder with 4 leading spaces preceding a left justified number, andfollowed by a single blank line.
Sample Input
90
1234567891
18991325453139
12745267386521023
-1
Sample Output
2
3
3
5 1234567891 3
3
13
179
271
1381
2423 30971
411522630413 题意:将给出的N分解成几个素数的乘式, 但不包括1 做法: 从2开始遍历到N的开方数, 每一个因子都拿去重复的判断是否能对其整除, 若能, 输出因子i, 更新N, 如此做还能提高效率~ AC代码:
#include<stdio.h>
#include<math.h> int main() {
long long int N;
while(scanf("%lld", &N) != EOF) {
if(N < 0)
break;
for(int i = 2; i <= sqrt(N); i++) {
while(N % i == 0) {
printf(" %d\n", i);
N = N / i;
}
}
if(N > 1)
printf(" %lld\n", N);
printf("\n");
}
return 0;
}
UVA 10392 (13.07.28)的更多相关文章
- UVA 568 (13.07.28)
Just the Facts The expression N!, read as `` N factorial," denotes the product of the first N ...
- UVA 408 (13.07.28)
Uniform Generator Computer simulations often require random numbers. One way to generatepseudo-ran ...
- UVA 299 (13.07.30)
Train Swapping At an old railway station, you may still encounter one of the lastremaining ``train ...
- UVA 140 (13.07.29)
Bandwidth Given a graph (V,E) where V is a set of nodes and E is a set of arcsin VxV, and anorderi ...
- 07-09 07:28:38.350: E/AndroidRuntime(1437): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.googleplay.ui.activity.MainActivity" on path: DexPathList[[zip file "/data/app/c
一运行,加载mainActivity就报错 布局文件乱写一通,然后急着运行,报莫名其妙的错误: 07-09 07:28:38.350: E/AndroidRuntime(1437): Caused b ...
- Feb 5 13:07:52 plugh rsyslogd-2177: imuxsock begins to drop messages from pid 12105 due to rate-limiting
FROM:https://www.nri-secure.co.jp/ncsirt/2013/0218.html SANSインターネットストームセンターのハンドラであるJohannes Ullrichが ...
- UVA 10194 (13.08.05)
:W Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (ameri ...
- Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33
06-图2 Saving James Bond - Easy Version(25 分) This time let us consider the situation in the movie &q ...
- UVA 253 (13.08.06)
Cube painting We have a machine for painting cubes. It is supplied withthree different colors: blu ...
随机推荐
- User、Role、Permission数据库设计ABP
ABP 初探 之User.Role.Permission数据库设计 (EntityFramework 继承的另一种使用方法) 最近群里(134710707)的朋友都在讨论ABP源码,我把最近学习的内容 ...
- HDU 5281 Senior's Gun (贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还 ...
- matlab配置Libsvm 防止备忘录
1 首先我们要下载一个Libsvm 工具箱 其中,这一切都可以被下载到 2 我们解包 我解压在桌面上 住址C:\Users\Administrator\Desktop\libsvm 3打开matlab ...
- JS function立即调用的几种写法
//立即执行 (function () { alert(1) })() //立即执行 !function () { alert(1) }() //立即执行 +function () { alert(1 ...
- SQLServer 使用 @@ERROR
原文:SQLServer 使用 @@ERROR 使用 @@ERROR 如果最后的 Transact-SQL 语句执行成功,则 @@ERROR 系统函数返回 0:如果此语句产生错误,则 @@ERROR ...
- DevExpress中获取RichTextEdit中RichEditControl的两种方式
方式一: var rte = sender as RichTextEdit; control = rte.Controls[] as RichEditControl; 方式二: PropertyInf ...
- 解决tomcat占用8080端口
怎么解决tomcat占用8080端口问题图文教程 怎么解决tomcat占用8080端口问题 相信很多朋友都遇到过这样的问题吧,tomcat死机了,重启eclipse之后,发现 Se ...
- wamp 已安装cakephp Fatal error: You must enable the intl extension to use CakePHP. in XXX
今wamp已安装cakephp3.x什么时候.报告这样的错误:Fatal error: You must enable the intl extension to use CakePHP. in D: ...
- java基金会 之 HashMap统计csvWord文档
一:知识的补充( 这个HashMap Map 和 c++的Map还是有非常大的区别,惊人的差异大的人,当然,两者的作用是相同的,但函数名出一个非常大的.即使iterator的差是非常大的 ) (1)H ...
- iOS_22自定义键盘工具栏
最后效果图: Main.storyboard KeyboardTool.xib watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ ...