Announcements, comments, ideas, feedback, and "How do I... ?" questions
Gekkey
Posts: 1 Joined: Mon Jan 17, 2011 1:58 am
Post
by Gekkey » Mon Jan 17, 2011 2:11 am
Alright. I am here to ask a question. I don't know if this belongs here or not.
I am using python and am on problem #10.
My program was going incredibly slow until I changed it from:
Code: Select all
for i in range(3, 2000000, 2):
for i in range(2, x, 2):
to:
Code: Select all
for i in range(3, 2000000, 2):
for i in range(2, x**0.5+1, 2):
I had seen that on other people's prime tests.
My question is: Why does this work?
|_|0|_|
|_|_|0|
|0|0|0|
TripleM
Posts: 384 Joined: Fri Sep 12, 2008 3:31 am
Post
by TripleM » Mon Jan 17, 2011 2:38 am
Suppose j is a factor of i. Then so is i/j. Can both j and i/j be more than sqrt(i)?