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 ...
随机推荐
- 开始学习java
.net 许久 看网络java猿飞计划,感觉成了少数类,学校为它,有多难不,有着vb,C,javascript和vs基金会,这并不是说一些语法和框架的熟悉做,搞两天,以一个开发环境,myeclipse ...
- webservice发送字符串
假设只是发送一个字符串client,这是很easy,只需要输入xfire包,编写接口,编写的实现方法.变化. 假设你要传输的数组或自定义类.到用于接口准备的需要agexis文件.更复杂. 尝试传输这些 ...
- c/c++和java达到swap不同功能
首先我们来看看c/c++实施swap性能 void swap ( int & a, int & b) { int Temp; temp = a; a = b; b = temp; } ...
- CSDN专家吐槽实录
今天打开CSDN发现界面上的几个图标发生了变化,一个小小的变化,却引起了诸多CSDN专家对CSDN社区未来发展的思考,我特意从群里讲对话黏贴出来,希望各位能给予积极评价和建议. 你已经是群成员了,和大 ...
- BCM策略路由交换芯片
BCM几个交换芯片的寄存器和相关的路由 EGR_L3_NEXT_HOP.EGR_L3_INTF.ING_L3_NEXT_HOP BCM XGS系列SDK中和路由相关的几个命令 l3 l3table. ...
- Swift语言指南(二)--语言基础之注释和分号
原文:Swift语言指南(二)--语言基础之注释和分号 注释 通过注释向自己的代码中注入不可执行的文本,作为你自己的笔记或提示.Swift编译器运行时会忽略注释. Swift的注释与C语言极其相似,单 ...
- hdu2203 KMP水的问题
两种方法 首先是纯KMP #include<stdio.h> #include<string.h> #include<iostream> using nam ...
- POJ3342——Party at Hali-Bula
Party at Hali-Bula Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5418 Accepted: 192 ...
- Python的html和xml解析库Beautiful Soup
网站:http://www.crummy.com/software/BeautifulSoup/ 版权声明:本文博主原创文章,博客,未经同意不得转载.
- Backup and Recovery Strategies1
2.1.Data Recovery Strategy Determines Backup Strategy 在设计备份策略.如若数据恢复需求和数据恢复战略启动.每种类型的数据恢复需要你采取相应的备份类 ...