OCAJP 7
OCAJP 7
I hate signatures!
OCAJP 7
Rajith Pemabandu wrote:You need a long definitely to achieve a solution. (long (2)^63 to ((2^63)1) range) 64 bits.
OCAJP 7
OCAJP 7
Because the compiler is designed to look for breaches of the rules of syntax. It cannot be expected to look for logic errors. That is what programmers are there for.Dana Ucaed wrote:Why the compiler didn't say anything?
Dana Ucaed wrote:if I have
Outputs are:
2541865828329
754810903
All things are lawful, but not all things are profitable.
OCAJP 7
I presume that is the transverse product of consecutive digits, rather than the String whose digits you want to multiply. Otherwise the transverse product would be 0.Dana Ucaed wrote:. . . Output is:2091059712 . . . . why don't appear overflow when I used int as type of variable. . . .
OCAJP 7
Campbell Ritchie wrote:2091059712's prime factors are 2⁹ × 3⁵ × 7⁵, which suggests that you have 7s, 3/6/9s and 2/4/8s in the text you are multiplying, and no 5/0s. Five 7s, but I can't tell how many of the other digits. It is very unlikely that you got that number from an overflow. Please show us the input which produced that output.
OCAJP 7
OCAJP 7
Dana Ucaed wrote:If the overflow is not the reason , what is the reason?
Campbell Ritchie wrote:2091059712's prime factors are 2⁹ × 3⁵ × 7⁵, which suggests that you have 7s, 3/6/9s and 2/4/8s in the text you are multiplying, and no 5/0s. Five 7s, but I can't tell how many of the other digits. It is very unlikely that you got that number from an overflow. Please show us the input which produced that output.
I hate signatures!
Two 9s and a 6: there's the 3⁵ if we divide by 2.Piet Souris wrote:. . . 9781797784617 . . .
Dana Ucaed wrote:I know limits of datatype int.
Can someone say me the reason for which Output is:2091059712??
Aaaaaaaaaaaaaaaah! That is why it has those nice lots and lots of factors.Carey Brown wrote:. . . That is the largest product that your program could find that DIDN'T OVERFLOW. . . .
Campbell Ritchie wrote:
Two 9s and a 6: there's the 3⁵ if we divide by 2.Piet Souris wrote:. . . 9781797784617 . . .
Five 7s: There's the 7⁵
Two 8s, a 4 and a 6: if we divide that by 3 we get 2⁹
Spot on It just so happens that this number will fit into the limits of an int without overflow errors.
Notice you have two 1s, which count as a unit for multiplication. Remembering what the products of other digits would be, work out what would be an annihilator. When you find that annihilator, you can move on to the next thirteen characters following it. I think PS is hinting about the same thing.
OCAJP 7
OCAJP 7
Piet Souris wrote:
Campbell Ritchie wrote:2091059712's prime factors are 2⁹ × 3⁵ × 7⁵, which suggests that you have 7s, 3/6/9s and 2/4/8s in the text you are multiplying, and no 5/0s. Five 7s, but I can't tell how many of the other digits. It is very unlikely that you got that number from an overflow. Please show us the input which produced that output.
9781797784617
(in the code I gave, use this:
This code is for Java 8?
I used Java 7.
@Dana,
with Project Euler, when brute force is a viable solution (by far not always applicable), it is always nice to look out for some optimizations. For instance, say:
S0 = d1 * d2 * d3 * ... * d13
S1 = d2 * d3 * d4 * ... * d13 * d14
can you write: S1 = S0 * alpha? And thus: what is alpha? And what if alpha < 1? Or > 1? And what has this to do with the excersize?
OCAJP 7
Dana Ucaed wrote:
Carey Brown said it is overflow, but Campbell said it's not overflow.
What is the truth?
That is the largest product that your program could find that DIDN'T OVERFLOW. Other products (including the correct answer) did overflow and ended up being negative numbers which were less than maximumProduct.
All things are lawful, but not all things are profitable.
SCJP 1.4  SCJP 6  SCWCD 5  OCEEJBD 6  OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4  SCJP 6  SCWCD 5  OCEEJBD 6  OCEJPAD 6
How To Ask Questions How To Answer Questions
I wasn't selected to go to mars. This tiny ad got in ahead of me:
Sauce Labs  World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/SauceLabsWorldLargestContinuous
