Largest prime factor
problem 3:Largest prime factor
题意:求600851475143的最大的质因数
代码如下:
#ifndef PRO3_H_INCLUDED
#define PRO3_H_INCLUDED
#include "prime.h"
namespace pro3{
long long solve(){
;;
;i*i<=n;++i)
){
if(isPrime(n/i))return n/i;
else if(isPrime(i))maxn=i;
}
>maxn?:maxn;
}
}
#endif // PRO3_H_INCLUDED
其中,bool isPrime(long long x)如下(后面不再赘述):
bool isPrime(long long x){
);
;i*i<=x;++i)
);
;
}
bool isPrime(long long x)
Largest prime factor的更多相关文章
- The largest prime factor(最大质因数)
1. 问题: The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number ...
- HDOJ(HDU) 2136 Largest prime factor(素数筛选)
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- (Problem 3)Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...
- 2136 Largest prime factor(打表)
Problem Description Everybody knows any number can be combined by the prime number.Now, your task is ...
- Problem 3: Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...
- R语言学习——欧拉计划(3)Largest prime factor 求最大质因数
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...
- 【ACM】Largest prime factor
/*打表把素数能组合的数先设置成相应的位数*/ /* if n equals two and n is No.1 position of prime factors so four position ...
- [暑假集训--数论]hdu2136 Largest prime factor
Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...
随机推荐
- DynamicResource与StaticResource的区别
原文:DynamicResource与StaticResource的区别 2008-06-20 12:16:12 静态资源在第一次编译后即确定其对象或值,之后不能对其进行修改.动态资源则是在运行时决定 ...
- 如何给TableLayout加边框
呵呵,其实很简单 就是将TableLayout定义一种颜色,在给TableRow定义一种颜色.通过TableRow的layout_margin挤出一个像素的宽度就变成了TableLayout的宽度.这 ...
- 【C#版本详情回顾】C#2.0主要功能列表
泛型 优点:类型安全/重用代码/提升性能 应用:泛型接口.泛型类.泛型类型参数.泛型方法.泛型事件和泛型委托 命名空间:System.Collections.Generic 特性:泛型约束,defau ...
- hrift 的序列化机制
Thrift 个人实战--Thrift 的序列化机制 前言: Thrift作为Facebook开源的RPC框架, 通过IDL中间语言, 并借助代码生成引擎生成各种主流语言的rpc框架服务端/客户端代码 ...
- C++ const关键字用法详解
1const char*, char const*, char*const的区别问题几乎是C++面试中每次都会有的题目. 事实上这个概念谁都有只是三种声明方式非常相似很容易记混. Bjarne在他的T ...
- iOS基础 - 定时器
1.可以完成的功能:每隔一段时间做一些固定的事情 2.创建定时器 1> 方法1 NSTimer *timer = [NSTimer timerWithTimeInterval:1.5 targe ...
- Nginx+Tomcat+Memcached实现tomcat集群和session共享
一.Nginx安装 详见前文:http://www.cnblogs.com/yixiwenwen/p/3574097.html 二.memcached安装和启动 详见前文:http://www.cnb ...
- Python多线程的创建,相关函数和守护线程的理解
一:多线程的创建 threading库创建线程有两种方式,函数式和继承式 1)函数式 def func(): print 'Starting' print 'Ending' t=threadin ...
- Forms Authentication in ASP.NET MVC 4
原文:Forms Authentication in ASP.NET MVC 4 Contents: Introduction Implement a custom membership provid ...
- spring.NET的依赖注入
谈谈自己了解的spring.NET的依赖注入 spring.net里实现了控制反转IOC(Inversion of control),也即依赖注入DI(Dependency Injection), ...