Denote by R(N) the integer obtained by reversing the digits of a positive integer N.
Determine the largest integer that is certain to
divide N4 - (R(N))4, with N > R(N), regardless of the choice of N.
DefDbl A-Z
Dim crlf$, sofar
Private Sub Form_Load()
ChDir "C:\Program Files (x86)\DevStudio\VB\projects\flooble"
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
For n = 10 To 10000
rn = reverse(n)
If n > rn Then
If flag = 0 Then
sofar = n - rn
flag = 1
Else
sofar = gcd(sofar, n - rn)
End If
Text1.Text = Text1.Text & Str(n) & Str(rn) & Str(sofar) & crlf
DoEvents
End If
Next
Text1.Text = Text1.Text & crlf & "done"
End Sub
Function reverse(n)
s$ = LTrim(Str(n))
v = 0
For i = Len(s$) To 1 Step -1
v = 10 * v + Val(Mid(s$, i, 1))
Next
reverse = v
End Function
Function gcd(a, b)
x = a: y = b
Do
q = Int(x / y)
z = x - q * y
x = y: y = z
Loop Until z = 0
gcd = x
End Function
finds the GCD among the formulas coming from all N tested as 9.
|
Posted by Charlie
on 2014-07-22 11:58:31 |