![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
Ok, i'm doing the challenges at mathschallenge.net.
I'm doing problem 3 right now. Here is the link:http://mathschallenge.net/index.php?...=problems&id=3 I thought i had my code right, as the example number (13195) shows 5,7,13 and 29 using my program. So i used it with the proper number (317584931803), and it didn't work, it gave me this error: Traceback (most recent call last): File "maths3.py", line 18, in ? findFactors(317584931803) File "maths3.py", line 12, in findFactors for i in range (1,x): OverflowError: range() result has too many items Ok, so the range() list won't hold that many characters, how will i go about doing this problem now? Here is my code: #! /usr/bin/env python
from math import sqrt
factors=[]
def primeCheck(y):
if y < 2:
return False
for i in range(int(sqrt(y)) + 1)[2:]:
if y % i == 0:
return False
return True
def findFactors(x):
for i in range (1,x):
if (x % i) == 0:
if primeCheck(i):
factors.append(i)
print factors
findFactors(317584931803) If i don't reply for a while it is because i'm going away for a week to the isle of whight. ![]()
__________________
Join us at #programmingforums @ irc.freenode.net! My software never has bugs. It just develops random features.
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Try using xrange instead of range.
|
|
|
|
|
|
#3 |
|
Expert Programmer
|
Thanks, it works.
__________________
Join us at #programmingforums @ irc.freenode.net! My software never has bugs. It just develops random features.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|