UVA10392 Factoring Large Numbers
2016-05-19 20:58
239 查看
思路:质因分解..
One of the central ideas behind much cryptography is that factoring large numbers is computationally
intensive. In this context one might use a 100 digit number that was a product of two 50 digit prime
numbers. Even with the fastest projected computers this factorization will take hundreds of years.
You don’t have those computers available, but if you are clever you can 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’s long long int datatype, however scanf and printf do not appear to handle
this datatype correctly, so you must do your own I/O conversion.
Output
Each positive number from the input must be factored and all factors (other than 1) printed out. The
factors must be printed in ascending order with 4 leading spaces preceding a left justified number, and
followed 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
#include<iostream> #include<cmath> #include<cstdio> using namespace std; #define LL long long int main() { LL num; while(cin>>num) { if(num < 0) break; for(LL i = 2; i <= (int)sqrt(num); i++) while(num % i == 0) { cout<<" "; cout<<i<<endl; num /= i; } if(num > 1) cout<<" "<<num<<endl; cout<<endl; } }
One of the central ideas behind much cryptography is that factoring large numbers is computationally
intensive. In this context one might use a 100 digit number that was a product of two 50 digit prime
numbers. Even with the fastest projected computers this factorization will take hundreds of years.
You don’t have those computers available, but if you are clever you can 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’s long long int datatype, however scanf and printf do not appear to handle
this datatype correctly, so you must do your own I/O conversion.
Output
Each positive number from the input must be factored and all factors (other than 1) printed out. The
factors must be printed in ascending order with 4 leading spaces preceding a left justified number, and
followed 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
相关文章推荐
- HTML2
- Matrix
- java抽象类,接口
- php页面用include引入header.php出现头部上边有一行空白
- 第12周课后实践②
- PAT 团体程序设计天梯赛-练习集 L2-006. 树的遍历【数据结构】
- 给动态增加的元素添加事件
- 文件读写: 二进制方式和文本方式的区别
- C++类型安全
- 静态函数库与动态函数库(共享库)的创建
- hiho1043 #1043 : 完全背包
- YII的lazy loading
- hge source explor 0x2 windows module
- Ansible 自动化运维工具之when条件语句
- 欢迎使用CSDN-markdown编辑器
- Linux习题集(常用命令和shell)
- 【c程序设计语言(第二版)】素数
- hdu1163Eddy's digital Roots(九余数定理+同余定理)
- UVA350 Pseudo-Random Numbers
- 面试题03 二维数组中的查找