Page 2 of 3
Re: Problem 007
Posted: Wed May 13, 2009 5:03 pm
by Assato
Yep, we have to make sure not to post hints here.... as you advance, for future problems the threads won't be locked (they lock with 100 posts) and you'll be able to post questions like this on the problem forum.
Re: Problem 007
Posted: Wed May 13, 2009 5:08 pm
by daniel.is.fischer
Ah, well, actually what he posted was basically already mentioned by euler on the first page of this thread, so I seem to have been a little overzealous.
And hints are okay, just make sure you don't post spoilers.
Re: Problem 007
Posted: Mon Apr 05, 2010 5:50 am
by ivan_adrian_k
I tried to produce the primes array by looping:
1. Assign the first prime (2) in the array
2. Loop for each odd integer larger than 2, try to divide it with each number in the array. (After improvement, I only try numbers in the array, not including 2, which are less than the square root of the integer.) If none divides the integer, the integer is appended to the array.
3. Since the first key for the array is 0, I take the array value with the key 10000. But I'm wrong. Can someone help me?
P.S. I use Visual Basic, very different from the others, maybe?
Re: Problem 007
Posted: Mon Apr 05, 2010 10:30 am
by TripleM
Have you tried checking, say, all numbers less than 100 to see if they match up with your list correctly?
Re: Problem 007
Posted: Mon Apr 05, 2010 11:07 am
by zwuupeape
I think there is a subtle mistake in your improvement. No need to go for 100 - the approach you describe should already give the wrong answer for numbers less than 10.
Re: Problem 007
Posted: Tue Apr 06, 2010 7:41 am
by ivan_adrian_k
Oh yes, I should use "less than or equal to" instead of just "less than". Thanks!
Problem 007
Posted: Tue Dec 07, 2010 11:48 pm
by error1954
Can someone explain to me why this code doesn't work?
Or rather why it doesn't output the right answer?
Thanks in advance.
Re: Problem 7
Posted: Wed Dec 08, 2010 12:16 am
by TripleM
In future please use threads that already exist - here's the one for problem 7:
viewtopic.php?f=50&t=1203
Also, as mentioned in the very big bright red section the top of the forum, please don't post code (even if it is wrong

) You can ask if someone is interested in reading your code then sending it in a PM if necessary.
A moderator will fix the above two issues, but since I've already seen your code - you might like to have another look at the definition of a prime number. Just because it isn't divisible by 2, 3, 5, or 7 doesn't make it a prime number - 121 is not a prime number but your program says it is. Neither is 97*37 = 3589.
Re: Problem 7
Posted: Wed Dec 08, 2010 12:18 am
by sfabriz
You need to take a better look to the definition of prime number, since you're checking for divisibility only with a bunch of primes. Moreover, as stated in the red section, please don't post any spoilers or code snippets within this forum.
Cheers
Re: Problem 7
Posted: Wed Dec 08, 2010 1:07 am
by error1954
Well actually I was checking for primes using the sieve of eratosthenes.
Or at least I thought I was.
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Is there a better way though?
Re: Problem 7
Posted: Wed Dec 08, 2010 2:52 am
by TripleM
Have a look at step 5 on the page you linked to. It doesn't say to stop when p = 7. But as mentioned above, this forum isn't for discussing approaches to problems. If you want further help, send me a PM.
(@mods - feel free to delete my posts if any of this thread needs deleting)
Re: Problem 7
Posted: Wed Dec 08, 2010 4:53 am
by rayfil
@error1954
Either you don't know how to edit your posts or you didn't bother with TripleM's suggestion about posting code. I thus had to remove it myself.
Once more, NO CODE should be posted in any of the threads on this forum.
Re: Problem 007
Posted: Tue May 24, 2011 11:32 pm
by Simmons
I got a working sieve for all int numbers, but I am having a problem for longs (Java). I have variables that I am using to reference a point in the array, but those variables are longs and I get errors because it can't convert long to int or something.
Re: Problem 007
Posted: Wed May 25, 2011 1:20 am
by rayfil
I don't know what you mean by "long" and "int" in your language but I can assure you that everything in this problem can be done with 32-bit variables.
Re: Problem 007
Posted: Wed May 25, 2011 1:40 am
by sivakd
Java arrays can have a length up to 2147483647 (
http://stackoverflow.com/questions/3038 ... ximum-size) which fits within an int (for java) and this problem doesn't require going beyond that.
Re: Problem 007
Posted: Wed May 25, 2011 2:25 am
by davidFashion
Simmons wrote:I have variables that I am using to reference a point in the array, but those variables are longs
In Java, an array index must be an int. For those that do not know Java, and int is a 32-bit integer.
Simmons wrote:I get errors because it can't convert long to int or something.
When using a long as an index to an array, there are two options. Cast the long to an int, or change the data type of the variable to an int.

Problem 007
Posted: Thu Jun 02, 2011 3:24 pm
by IncanD
I am totally stumped. I've been working on this problem for about a week now and I just can't seem to get what I'm doing wrong. Firstly, what I had in mind was trying to start off with the Sieve of Eratosthenes in order to get all of the prime numbers before 'n' and store it in array 'a'. After doing so, I count every number in 'a' that is not crossed out (crossed out elements in the array have a value of -1) and store that count in an integer var named 'count'. I then continue to displaying a[count] in order to get the answer. However, the problem arises in the actual development of the Sieve of Eratosthenes. I seem to have caught myself stuck in an infinite loop and I honestly don't know what to do. Since I cannot post any code snippets of any sort, would anybody be willing to share e-mails with me?
Many thanks,
Fernand
Re: Problem 007
Posted: Fri Jun 03, 2011 1:20 am
by rayfil
We realize this is your first post. But please, do not start a new topic when one is already available. There's a search box at the top of the page. All problems below #100 have leading 0's to make them a 3-digit number for ease of sorting and searching.
Re: Problem 007
Posted: Fri Jun 03, 2011 7:17 am
by Lord_Farin
IncanD wrote:Since I cannot post any code snippets of any sort, would anybody be willing to share e-mails with me?
If your language is Mathematica, Java, C, C++ or Haskell, or you deem at least one of those to be similar enough, you can use the forum's PM functionality to send me your code.
Re: Problem 007
Posted: Wed Jul 20, 2011 2:48 pm
by coziroyc
I have found the solution for this problem, double checked my output past 100 and also checked my solution on a different website which says it agrees with my answer. Is there anyway that I could email my solution to someone and they could verify whether it is right or wrong. I feel like there must be a glitch in the solution submission for me. I know this sounds strange, but I am positive this is the right solution.