Thread: Mod Function
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dana DeLouis Dana DeLouis is offline
external usenet poster
 
Posts: 947
Default Mod Function

... = (CDec(n) - m * Int(CDec(n) / m))
I was able to go as far as mod(10e28;97),


Hi Diogo. :) You are so close. A favorite subject of mine. You may
find this of interest.
For your stated problem, your large first number is written in the form of
10^x
When an intermediate number is large (ie 10^32), there is a Number Theory
procedure that is much more efficient by avoiding such a large calculation.
Problems of the form Mod(n^m,x) are usually not calculated like this
directly, but are usually calculated by a function that usually goes by the
name POWERMOD.
If you do an internet search, you should be able to find a number of
different techniques.

To give you some idea, the following calculation would be hard.

81703395 ^ 81703395

It has over 646,000,000 digits in the answer.

Given that, who knows how astronomically large the first number is he

Mod(123456789012345678901234567 ^ 123456789012345678901234567, 97)

However, Excel can calculate this easily and quickly.
(Mine has been modified to do these types of calculations.)

given that n = 123456789012345678901234567
calculate Mod(n^n,97)

?PowerMod(n, n, 97)
14

So, given that, these are easy.

'Mod(10^29,97)
Debug.Print PowerMod(10, 29, 97)

'Mod(10^33,97)
Debug.Print PowerMod(10, 33, 97)

'Mod(10^999,97)
Debug.Print PowerMod(10, 999, 97)

Returns:
57
28
77

--
Good Luck
HTH
Dana DeLouis


"Diogo" wrote in message
...
Update:

Using:

Function MyMod(n, m)
MyMod = (CDec(n) - m * Int(CDec(n) / m))
End Function

I was able to go as far as mod(10e28;97), anything higher and it returns
#VALUE!

I need to go as far as 10e32, almost there :)

Any thoughts?