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 ...
随机推荐
- javascript活动
在javascript倘若有知识的三个方面.事件的第一,流程,其次,事件处理,第三,事件对象.下面就我个人的理解,,分别讲述一下这三个方面的内容. 第一.事件流 事件流指的是事件依照一定的顺序触发.它 ...
- html + CSS
Html 1 html基本标签 1.1 html文件结构 <!DOCTYPE html PUBLIC "-//W3C//DTDXHTML 1.0 Transitional//EN&qu ...
- hdu 4972 A simple dynamic programming problem(高效)
pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...
- 从头开始学JavaScript (十一)——Object类型
原文:从头开始学JavaScript (十一)--Object类型 一.object类型 一个object就是一系列属性的集合,一个属性包含一个名字(属性名)和一个值(属性值). object对于在应 ...
- 华为G520联通版刷机包 基于MIUI CM11新 平稳 稳定
ROM介绍 刷先配置双卡:"设定-安卓原生设置-双卡套-配置订阅",否则,无信号 使开发人员选项方法:"设定-安卓原生设置-关于手机-发布"连续点击版本 启用A ...
- iOS开发分析"秘密"App内容页面的效果(两)
@我前几天写的"秘密"的Cell制品的效果,想要的效果还是有差距,并且扩展性非常不好,于是重写封装,把总体视图都放到scrollView中,基本是和secret app 一模一样的 ...
- ASP.NET的CMS
最受欢迎的ASP.NET的CMS下载 1. Umbraco 项目地址 | 下载 Umbraco是一个开放源码的CMS内容管理系统,基于asp.net建立,使用mssql进行存储数据. 使用Umbrac ...
- Forms身份验证和基于Role的权限验证
Forms身份验证和基于Role的权限验证 从Membership到SimpleMembership再到ASP.NET Identity,ASP.NET每一次更换身份验证的组件,都让我更失望.Memb ...
- DBUtils的使用
DButils是apache旗下Commons项目中的一个JDBC工具包,它可以为帮助我们简化对JDBC的操作,但它并不是一个ORM框架,只是可以为我们执行sql,并将返回的ResultSet转化成我 ...
- CSS_img标签usemap属性图片中选择区域加入超链接
例子: <IMG usemap="#Map" alt="" src="/images/banbian.jpg"> <map ...