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 ...
随机推荐
- 【Cocos得知】技术要点通常的积累
1.粒子特效 CCParticleSystem*sp = CCParticleSnow::create(); sp->setTexture(CCTextureCache::sharedTextu ...
- android activity 后的形式 藏
activity 希望的形式 于AndroidManifest.xml 建立 theme 属性 <activity android:name="zicox.u ...
- Linux而不必进入password登陆自己主动sshserver方法
使用OpenSSH在linux通过登陆sshserver时间,系统会提示您输入每次password,和用途vim 的netrw保存编辑后的每一个变化必须失去远程文件时,插件password,很多麻烦. ...
- 详解JMeter函数和变量
JMeter函数可以被认为是某种特殊的变量,它们可以被采样器或者其他测试元件所引用.函数调用的语法如下: ${__functionName(var1,var2,var3)} 其中,__function ...
- .NET中IDisposable接口的基本使用
首先来看MSDN中关于这个接口的说明: [ComVisible(true)] public interface IDisposable { // Methods void Dispose(); } 1 ...
- JavaEE(1) - Weblogic 服务器管理的数据源
JBoss下载: http://jbossas.jboss.org/downloads http://www.cnblogs.com/xw-cnblogs/articles/2439969.html ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- uboot中raise:Signal #8 caught的根本原因
在移植uboot时编译一切正常,但uboot启动中载入自己写的网卡驱动出现故障,一直在打印raise:Signal #8 caught google 百度了一番,也有非常多人遇到了这个问题,大家都说 ...
- c# p2p 穿透(源码加密)
http://blog.oraycn.com/ESFramework_Demo_P2P.aspx 测试,完全OK! 我很喜欢这个.可以源码是加密的!我希望实现 web 版本的p2p视频观看,aehy ...
- C#-面向对象的多态思想 ---ShinePans
总结: 多态是面向对象的核心.---------能够理解为一个方法,多种实现, 在这里能够用虚方法,抽象类,接口能够实现多态 1.首先利用接口来实现多态: 接口相当于"功能,"接口 ...