Problem 007

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.

This forum is NOT meant to discuss solution methods for a problem.

In particular don't post any code fragments or results.

Don't start begging others to give partial answers to problems

Don't ask for hints how to solve a problem

Don't start a new topic for a problem if there already exists one


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
User avatar
Assato
Posts: 13
Joined: Sun Apr 19, 2009 4:21 pm

Re: Problem 007

Post 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.
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 007

Post 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.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
ivan_adrian_k
Posts: 8
Joined: Sat Apr 03, 2010 6:20 am

Re: Problem 007

Post 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?
TripleM
Posts: 384
Joined: Fri Sep 12, 2008 3:31 am

Re: Problem 007

Post by TripleM »

Have you tried checking, say, all numbers less than 100 to see if they match up with your list correctly?
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 007

Post 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.
ivan_adrian_k
Posts: 8
Joined: Sat Apr 03, 2010 6:20 am

Re: Problem 007

Post by ivan_adrian_k »

Oh yes, I should use "less than or equal to" instead of just "less than". Thanks!
error1954
Posts: 2
Joined: Tue Dec 07, 2010 10:43 pm

Problem 007

Post by error1954 »

Code: Select all

snip
Can someone explain to me why this code doesn't work?
Or rather why it doesn't output the right answer?
Thanks in advance.
TripleM
Posts: 384
Joined: Fri Sep 12, 2008 3:31 am

Re: Problem 7

Post 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.
User avatar
sfabriz
Posts: 175
Joined: Thu Apr 06, 2006 12:18 am
Location: London - UK

Re: Problem 7

Post 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
Image
error1954
Posts: 2
Joined: Tue Dec 07, 2010 10:43 pm

Re: Problem 7

Post 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?
TripleM
Posts: 384
Joined: Fri Sep 12, 2008 3:31 am

Re: Problem 7

Post 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)
User avatar
rayfil
Administrator
Posts: 1412
Joined: Sun Mar 26, 2006 5:30 am
Location: Quebec, Canada
Contact:

Re: Problem 7

Post 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.
When you assume something, you risk being wrong half the time.
Simmons
Posts: 2
Joined: Wed May 18, 2011 4:04 pm

Re: Problem 007

Post 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.
User avatar
rayfil
Administrator
Posts: 1412
Joined: Sun Mar 26, 2006 5:30 am
Location: Quebec, Canada
Contact:

Re: Problem 007

Post 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.
When you assume something, you risk being wrong half the time.
sivakd
Posts: 217
Joined: Fri Jul 17, 2009 9:37 am
Location: California, USA
Contact:

Re: Problem 007

Post 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.
Image
puzzle is a euphemism for lack of clarity
davidFashion
Posts: 14
Joined: Fri Mar 04, 2011 10:53 pm

Re: Problem 007

Post 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.

Image
IncanD
Posts: 1
Joined: Thu Jun 02, 2011 3:12 pm

Problem 007

Post 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
User avatar
rayfil
Administrator
Posts: 1412
Joined: Sun Mar 26, 2006 5:30 am
Location: Quebec, Canada
Contact:

Re: Problem 007

Post 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.
When you assume something, you risk being wrong half the time.
User avatar
Lord_Farin
Posts: 239
Joined: Wed Jul 01, 2009 10:43 am
Location: Netherlands

Re: Problem 007

Post 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.
Image
coziroyc
Posts: 2
Joined: Wed Jul 20, 2011 2:36 pm

Re: Problem 007

Post 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.
Post Reply