Largest prime factor

Problem 3

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

The answer:

import math
def getLargestPrime(data):
list = []
i = 2
while i <= math.sqrt(data):
#while i <= data/2:
if data%i == 0 :
list.append(i)
data = (int)(data/i)
#i = 2
else:
i += 1
list.append(data)
return list number = 600851475143
list = getLargestPrime(number)
print(list)
print(list[len(list) -1])

when the length of list equals 1, it is a composite number

From this problem, how to figure out whether a number is prime number。The solution is as follows:

def isPrime(data):
i = 2
while i<= math.sqrt(data):
if data%i == 0:
return False
else:
i += 1
return True

Project Euler Problem3的更多相关文章

  1. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  2. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  3. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  4. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  5. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  6. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

  7. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  8. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

  9. Python练习题 048:Project Euler 021:10000以内所有亲和数之和

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

随机推荐

  1. DirectoryEntry_Properties属性的遍历(win2008)

    DirectoryEntry root = new DirectoryEntry(@"IIS://localhost/W3SVC"); string PInfo = "& ...

  2. SQLServer2008只能编辑前面200行数据

    设置编辑所有行:操作步骤:打开数据库-〉工具-〉选项-〉sqlserver对象资源管理器-〉命令 把200改为0,即可编辑所有行了

  3. java常见编码

    摘自:http://www.cnblogs.com/yaya-yaya/p/5768616.html 红色 主要点    灰色 内容      绿色  知识点    橘色 补充内容 几种常见的编码格式 ...

  4. 写出完整版的strcpy函数及其他如:strcat,strcmp,strstr的函数实现

    (---牛客网中刷题---)写出完整版的strcpy函数 如果编写一个标准strcpy函数的总分值为10,下面给出几个不同得分的答案: 2分 1 2 3 4 void strcpy( char *st ...

  5. ES6之Promise用法详解

    一 前言 本文主要对ES6的Promise进行一些入门级的介绍.要想学习一个知识点,肯定是从三个方面出发,what.why.how.下面就跟着我一步步学习吧~ 二 什么是Promise 首先是what ...

  6. poj2082 Terrible Sets(单调栈)

    Description Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all re ...

  7. Number Clicker CodeForces - 995E(双向bfs)

    双向bfs  注意数很大  用map来存 然后各种难受....

  8. Mybatis.xml文件中大于小于等于

    第一种写法: 原符号 < <= > >= & ' "替换符号 < <= > >= & &apos; "例如: ...

  9. RabbitMQ之集群搭建

    1.RabbitMQ集群模式RabbitMQ集群中节点包括内存节点(RAM).磁盘节点(Disk,消息持久化),集群中至少有一个Disk节点. 2.普通模式(默认)        对于普通模式,集群中 ...

  10. php错误日志

    php错误日志 /usr/local/php/var/log/php-fpm.log」—————————