Matthew Brown wrote:Well, a serial search like that is a very inefficient approach of solving it. You might want to read up about methods for calculating a Least Common Multiple. But in terms of the logic: don't you need to reset count for each new number?
(I'm also not sure why you've put i++ inside both branches of your if statement, instead of inside the loop statement as usual, but that doesn't affect the logic, just the readability).
SCJP 6 [ My stuff ]
Marc Cracco wrote:Also, to make this a little more efficient you could end the current loop iteration the first time % != 0 to prevent testing all the other cases unnecessarily.
You should look at the Java continue keyword.
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
The whole idea behind Project Euler is to reduce the problem to something simple which can be executed in a minute or under. I managed that problem 5 in about 1 minute — by hand, but with a calculator. If your program is churning, you have used a wrong algorithm and should start again.fred rosenberger wrote: . . . Project Euler problems can require a long time, if you don't use a clever method to reduce the steps. . . .
Campbell Ritchie wrote:
The whole idea behind Project Euler is to reduce the problem to something simple which can be executed in a minute or under. I managed that problem 5 in about 1 minute — by hand, but with a calculator. If your program is churning, you have used a wrong algorithm and should start again.fred rosenberger wrote: . . . Project Euler problems can require a long time, if you don't use a clever method to reduce the steps. . . .
Paper, pencil and eraser. That is what you need. Let the computer churn for hours; you can work out the correct algorithm in less time.
Campbell Ritchie wrote:The whole idea behind Project Euler is to reduce the problem to something simple which can be executed in a minute or under. I managed that problem 5 in about 1 minute — by hand, but with a calculator.(...)
Paper, pencil and eraser. That is what you need. (...)
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:Indeed, but I was hoping to avoid this, because it is not such an easy thing to do, and anyway much more work than needed.
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
Oh, no he wasn't. (British readers will understand that it is now December ).Piet Souris wrote:. . . This was probably what Campbell was hinting at. . . .
There are three kinds of actuaries: those who can count, and those who can't.
Campbell Ritchie wrote:I never signed up for Project Euler, either. Only, that question looked easy.
An integer is called elevenfree if its decimal expansion does not contain any substring representing a power of 11 except 1.
For example, 2404 and 13431 are elevenfree, while 911 and 4121331 are not.
Let E(n) be the nth positive elevenfree integer. For example, E(3) = 3, E(200) = 213 and E(500 000) = 531563.
Find E(10^18).
There are three kinds of actuaries: those who can count, and those who can't.
There's no knowlege that is not power!
There are three kinds of actuaries: those who can count, and those who can't.
There's no knowlege that is not power!
There are three kinds of actuaries: those who can count, and those who can't.
Campbell Ritchie wrote:Have you worked out what Fred means about prime factors? That is how you can do it, and how I did it. My solution has vanished, as I said it would.
There are three kinds of actuaries: those who can count, and those who can't.
OPPiet Souris wrote: . . . to whom are you asking this?
I am reluctant to leave the whole solution in case people simply copy it and solve Euler no 5 without understanding it.. . . I suggest you put it back . . .
I found some pretty shells, some sea glass and this lovely tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/ThreadBoostfeature
