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. 查询oracle sql运行计划,一个非常重要的观点--dba_hist_sql_plan

    该文章的作者给予了极大的帮助长老枯荣,为了表达我的谢意. 这适用于oracle db版本号oracle 10g或者更高的版本号. 之所以说这种看法是非常重要的,因为观点是有之一awrsqrpt报告没有 ...

  2. android 之 下载管理器 无论监测在当地的设计思路

    我相信你.让应用市场.或其它下载,想不管是什么地方监测进展情况.而且很好的实现. 这里分享一个相对简单的,并防止内存溢出等..我们用一个引用弱结合View进展更新方法. Map<String, ...

  3. bigdata_spark_源码修改_本地环境搭建_eclise

    Eclipse 下开发调试环境的配置该小节中使用的各项工具分别为:mac (Windows 7)+Eclipse Java EE 4.4.2+Scala 2.10.4+Sbt 0.13.8+Maven ...

  4. 【翻译】C#和.NET核心快速参考

    原文:[翻译]C#和.NET核心快速参考 PS:在网上看到的一篇C#总结,英文的,总结的还可以,都是基础知识,翻译给大家学习.文章结尾有英文原版.发布地址:http://www.cnblogs.com ...

  5. 汽车之家购买价格PC真正的原因阿拉丁

        网行业风起云涌,先是6月3号汽车之家天价竞购百度PC阿拉丁.接着今天又有消息说易车拿下百度移动阿拉丁.易车拿下百度移动阿拉丁能够想象.但PC阿拉丁被向来不屑流量购买,以自主流量自居的汽车之家拿 ...

  6. Android Bluetooth Stack: Bluedroid(五岁以下儿童):The analysis of A2DP Source

    1. A2DP Introduction The Advanced Audio Distribution Profile (A2DP) defines the protocols and proced ...

  7. 从用python做zoj1011发生Non-zero Exit Code错误说起

    近期做了浙大oj的第1011道题,遇见一件奇怪的事.这道题我用c++和php做,提交后都正确.可是用全然同样的逻辑改写成python代码提交后却产生了Non-zero Exit Code的判题结果.p ...

  8. 使用Net.Mail、CDO组件、JMail组件三种方式发送邮件

    原文:使用Net.Mail.CDO组件.JMail组件三种方式发送邮件 一.使用Net.Mail 需要服务器认证,大部分服务器端口为25. { MailMessage mailMsg = mailMs ...

  9. Junit指定测试运行顺序

    原文链接: Test execution order原始日期: 2012年12月06日本期: 2014年7月2日翻译人员: 铁锚 说明: Junit4.11版本号及以后才支持,建议升级到最新版本号. ...

  10. 顶级jQuery树插件

    顶级jQuery树插件 顶级jQuery树插件 2013-03-05 17:20 139人阅读 评论(0) 收藏 举报 jsTree JsTree是一个基于jQuery的Tree控件.支持HTML.J ...