# java- another problem

###
#1
Posted 27 January 2006 - 01:23 PM

###
#2
Posted 28 January 2006 - 12:28 PM

hint: use long for sum instead of int

were you able to figure out the sum problem with 1s and 3s?

**Edited by bdlt, 28 January 2006 - 02:24 PM.**

###
#3
Posted 28 January 2006 - 02:32 PM

###
#4
Posted 28 January 2006 - 02:45 PM

FYI -

last last number displayed was 499 993 500 021 - did you get this too?

the final sum(not displayed - add code to display it) should be 500 000 500 000

how do we know this final sum is correct?

for a sum from 1 to n of 1 + 2 + 3 + ... + n = n * (n + 1) / 2

multiply 1000000 * 1000001 then divide by 2 = 500 000 500 000

###
#5
Posted 04 February 2006 - 09:16 PM

What? If we're looping one million times then how can the last number be greater than one million (499,993,500,021)? In the OP, it was stated that you can only use 9's and 2's. The last number will be 999,999. 500,000,500,000 is the sum ofFYI -

last last number displayed was 499 993 500 021 - did you get this too?

the final sum(not displayed - add code to display it) should be 500 000 500 000

how do we know this final sum is correct?

for a sum from 1 to n of 1 + 2 + 3 + ... + n = n * (n + 1) / 2

multiply 1000000 * 1000001 then divide by 2 = 500 000 500 000

*all*numbers from 1 to 1000000 (inclusive)... this doesn't relate to the OP either. The sum I got was 41,169,513. Please verify this... I'm lost.

###
#6
Posted 04 February 2006 - 09:38 PM

my error - "whose digits consist only of 2s and 9s". didn't 'read' 2s AND 9s(and misread examples 2, 9, 29,...). so I'll post a new 2s and 9s ONLY number.

"The sum I got was 41,169,513. " - think about it. the last 10 numbers summed will almost reach 10 million, so 41 million is way too low.

edit - it looks like there may be NO sums whose digits consist only of 2s and 9s. did you get this too?

**Edited by bdlt, 04 February 2006 - 10:06 PM.**

###
#7
Posted 04 February 2006 - 10:04 PM

So what'd you get?"The sum I got was 41,169,513. " - think about it. the last 10 numbers summed will almost reach 10 million, so 41 million is way too low.

###
#8
Posted 04 February 2006 - 10:08 PM

and it looks like there are NO sums whose digits consist only of 2s and 9s. did you get this too?

###
#9
Posted 04 February 2006 - 10:17 PM

How do you figure? As I said before, this is the sum ofthis should be the sum: 500 000 500 000

*numbers from 1 to 1000000.*

**all**What do you mean?and it looks like there are NO sums whose digits consist only of 2s and 9s. did you get this too?

###
#10
Posted 04 February 2006 - 10:27 PM

for a sum from 1 to n of 1 + 2 + 3 + ... + n = n * (n + 1) / 2

multiply 1000000 * 1000001 then divide by 2 = 500 000 500 000

and it looks like there are NO sums whose digits consist only of 2s and 9s. did you get this too?

What do you mean?

there is not any sum that consists of only 2s and 9s.

1+2 = 3

1+2+3 = 6

1+2+3+4 = 10

1+2+3+4+5+6 = 21

1+2+3+4+5+6+7 = 28

and so on

as a test - try sums whose digits are only 0,1,2, and 9(I get 48)

what sums do you see that are only 2s and 9s?

###
#11
Posted 04 February 2006 - 10:35 PM

*must*be in your final sum.

###
#12
Posted 04 February 2006 - 10:49 PM

0 points for bdlt on this one.

edit - 41,169,513 looks correct

**Edited by bdlt, 04 February 2006 - 10:56 PM.**

### Similar Topics

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users