All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Prime divisors (Posted on 2005-01-04)
6300846559 is such that 6 is divisible by 2; 63, by 3; 630, by 5; 6300, by 7; and, in general, if you take its first N digits, it will be divisible by the N-th prime.

There is only one other such 10 digit number: can you find it?

 See The Solution Submitted by e.g. Rating: 3.7500 (4 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 re(3): Solution (VB program) | Comment 6 of 11 |
(In reply to re(2): Solution (VB program) by Penny)

The following code works in VB 5.0:

Dim prime(18)

Private Sub Command1_Click()
For i = 1 To 18
prime(i) = Choose(i, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61)
Next
Open "primediv.txt" For Output As #2
buildOn ""
Close 2
End Sub
Sub buildOn(s\$)
l = Len(s\$) + 1
had = 0
For i = 0 To 9
d\$ = LTrim\$(Str\$(i))
s1\$ = s\$ + d\$
v = Val(s1\$)
q = Int(v / prime(l))
r = v - q * prime(l)
If r = 0 Then
had = 1
If l = UBound(prime) Then
Print #2, s1\$; "*"
Else
buildOn s1\$
End If
End If
Next i
If had = 0 Then
le\$ = Right("   " + Str\$(Len(s\$)), 2) + " "
Print #2, le\$; s\$
End If
End Sub

The output was sent to a file as VB 5.0 has no console object. The resulting file was:

`000000000000000000* 5 00077 7 0056168 9 030147871 5 03080 5 03509 6 035750 6 060281 6 060944 5 06512 9 065897139 6 090311 8 09526467 7 0959276 4 2100 9 210769470 8 21560592 7 2401369 4 2408 7 2450890 5 24574 6 270270 6 270933 7 2751195 8 27588627 8 42009551 7 4207585 4 4256 6 450125 7 4508927 8 45507812 5 45573 5 48026 6 480922 7 4851086 7 4858753 6 600600 7 605553610 6300846559 7 6307476 5 63569 6 660114 7 6608818 9 665067264 5 66572 5 69025 6 690911 4 6951 7 6958644 4 8106 8 81554270 8 84007379 8 84073670 6 845689 6 870103 7 8708709 7 875056310 8757193191`

The asterisk after 000000000000000000 indicates that recursion was stopped deliberately.  Otherwise recursion would go on forever and of course run out of stack space.

In QuickBasic, a DOS program under a Command Prompt, extra stack space was made using

CLEAR , , 5000

but I'm sure Windows programs in VB have more stack space to begin with.  Just be sure that stack levels do not run out of hand.

 Posted by Charlie on 2005-01-04 18:29:01
Please log in:
 Login: Password: Remember me: Sign up! | Forgot password

 Search: Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (6)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2018 by Animus Pactum Consulting. All rights reserved. Privacy Information