D
Diogo
Need to calculate via Excel:
mod(13^271;162653)
Any thoughts????
Thanks
mod(13^271;162653)
Any thoughts????
Thanks
Hi Equingular,
(see my posting below)
Seems that we got the same mathematical idea... solved i a little differntly
in programming. Just tested your function versus my function on different
scenarios. Came out with the same result. Even for the calculation posted by
OP, ie. mod(13^271;162653)=102.308.
regards,
Lazzzx
Or you could note that =Mod(13^5,162653) returns 45987,
so that 152516 =Mod(45987^2) is equivalent to =Mod(13^10,162653)
hence 124726 =Mod(152516^2) is equivalent to =Mod(13^20,162653)
this accelerates the process used by Equiangular's algorithm.
I believe that 13^14 is the largest power of 13 that can be
represented accurately in a 64-bit floating-point number. So I would
not go any higher than that.
Two additional approaches that you could consider:
The simplest approach is to download Maxima from
http://maxima.sourceforge.net/index.shtml
and use it to directly calculate mod(13^271,162653);
Or you could note that =Mod(13^5,162653) returns 45987,
so that 152516 =Mod(45987^2) is equivalent to =Mod(13^10,162653)
hence 124726 =Mod(152516^2) is equivalent to =Mod(13^20,162653)
...
this accelerates the process used by Equiangular's algorithm.
Jerry
Joel said:I get the answer 145120 with the following code
Sub largemultiply()
Dim MyTotal As String
MyTotal = "13"
For i = 1 To 270
MyTotal = Multiply(MyTotal, "13")
Next i
Remainder = Divide(MyTotal, "162653")
End Sub
Function Multiply(parm1 As String, parm2 As String) As String
Multiply = ""
carry = 0
For i = 0 To (Len(parm1) - 1)
mychar1 = Mid(parm1, Len(parm1) - i, 1)
total = ""
For j = 0 To (Len(parm2) - 1)
mychar2 = Mid(parm2, Len(parm2) - j, 1)
prod = (Val(mychar1) * Val(mychar2)) + carry
carry = Int(prod / 10)
Remainder = prod Mod 10
total = Trim(CStr(Remainder)) & total
Next j
If Multiply = "" Then
Multiply = total
Else
Multiply = Add(Multiply, total, i)
End If
Next i
End Function
Function Add(Multiply, total, shift)
carry = 0
If shift > 0 Then
Add = Right(Multiply, shift)
Else
Add = ""
End If
For i = 0 To Len(total) - 1
If Len(Multiply) > (i + shift) Then
add1 = Val(Mid(Multiply, Len(Multiply) - (i + shift), 1))
Else
add1 = 0
End If
add2 = Val(Mid(total, Len(total) - i, 1))
Sum = add1 + add2 + carry
carry = Int(Sum / 10)
bit = Sum Mod 10
Add = bit & Add
Next i
If carry <> 0 Then
Add = carry & Add
End If
End Function
Function Divide(Quotent, Divisor)
Dim Remainder As Long
NDivisor = Val(Divisor)
NewQuotent = Val(Left(Quotent, Len(Divisor)))
loops = (Len(Quotent) - Len(Divisor))
For i = 0 To loops
Remainder = NewQuotent Mod NDivisor
If i <> loops Then
Newbit = Mid(Quotent, i + Len(Divisor) + 1, 1)
NewQuotent = (Remainder * 10) + Val(Newbit)
End If
Next i
Divide = Remainder
End Function
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.