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)的更多相关文章

  1. UVA 568 (13.07.28)

     Just the Facts  The expression N!, read as `` N factorial," denotes the product of the first N ...

  2. UVA 408 (13.07.28)

     Uniform Generator  Computer simulations often require random numbers. One way to generatepseudo-ran ...

  3. UVA 299 (13.07.30)

     Train Swapping  At an old railway station, you may still encounter one of the lastremaining ``train ...

  4. 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 ...

  5. 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 ...

  6. 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が ...

  7. UVA 10194 (13.08.05)

    :W Problem A: Football (aka Soccer)  The Problem Football the most popular sport in the world (ameri ...

  8. 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 ...

  9. UVA 253 (13.08.06)

     Cube painting  We have a machine for painting cubes. It is supplied withthree different colors: blu ...

随机推荐

  1. hdu 游乐场

    Problem Description   小时候,因为家里经济困难,小明从未去过游乐场,所以直到现在,他还心存遗憾.  最近,杭州刚建了一座游乐场,为了弥补儿时的遗憾,小明带了一笔钱迫不及待地要去体 ...

  2. jg-table 过程2 ( jgTable )

    jg-table ( jgTable )  添加一些新的功能,这是多行表头支持,要添加到,现在支持拖放多行表来改变头部的宽度, 假设设置cloneTheadToFoot 能够自己主动翻转多行表头,这也 ...

  3. hdu(2062)-Subset sequence 组合数学

    意甲冠军:查找集合{1,2,3...n}第一m一个排列子. 收集的线索所行的大小. 例两个元素的排列子集合按字典树排列是:{1},{1,2},{2},{2,1}: 解法:一个一个元素来确定,每次把剩余 ...

  4. Bootstrap-maxlength使用

    这是一个很酷jQuery实现Bootstrap小工具,输入用户同意的字符数.它可以让你显示字符用户插入的最大长度. 1.引入jquery.js及bootstrap-maxlength.js 2.给页面 ...

  5. Swift语言指南(九)--基本运算符

    原文:Swift语言指南(九)--基本运算符 运算符(operator)是用来检查,改变或合并值的一种特殊符号或短语.例如,加号运算符让两个数字相加(如:let i = 1 + 2),还有些更复杂的运 ...

  6. 皴EBS R12应用程序和数据库用户password

    1.假设你有一个EBS周围环境APPS用户password,能够打破用户的应用程序password 参考:Oracle EBS R12下怎样破解用户password 2,假设没有APPS用户passw ...

  7. 使用SQL Server Driver for PHP解决PHP连接MSSQL乱码的问题

    原文 使用SQL Server Driver for PHP解决PHP连接MSSQL乱码的问题 最近帮客户写了一个.net商城网站的发布接口,大家都知道.net一般都使用MSSQL数据库,但鱼丸不会. ...

  8. MySQL引擎介绍ISAM,MyISAM,HEAP,InnoDB

    MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎,就必须重新编译MYSQL. 在缺省情况下,MYSQL支持三个引擎:ISAM.MYISAM和HEAP.另外两种类型IN ...

  9. 使用OpenCV玩家营造出一个视频控制(没有声音)

    说明:OpenCV计算机视觉库,所以使用的图像或视频处理,因此,没有任何声音在播放视频的临时 软件:使用OpenCV制播放器(无声音) 功能说明:新建播放窗体.加入进度条能够拖动视频播放. 流程图: ...

  10. :link,:visited,:focus,:hover,:active详解

    原文::link,:visited,:focus,:hover,:active详解 CSS 又名 层叠样式表,所谓层叠,就是后面的样式会覆盖前面的样式,所以在样式表中,各样式排列的顺序很有讲究.   ...