Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Modular-exponentiation/Icon/modular-exponentiation.icon
Normal file
17
Task/Modular-exponentiation/Icon/modular-exponentiation.icon
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
procedure main()
|
||||
a := 2988348162058574136915891421498819466320163312926952423791023078876139
|
||||
b := 2351399303373464486466122544523690094744975233415544072992656881240319
|
||||
write("last 40 digits = ",mod_power(a,b,(10^40)))
|
||||
end
|
||||
|
||||
procedure mod_power(base, exponent, modulus) # fast modular exponentation
|
||||
if exponent < 0 then runerr(205,m) # added for this task
|
||||
result := 1
|
||||
while exponent > 0 do {
|
||||
if exponent % 2 = 1 then
|
||||
result := (result * base) % modulus
|
||||
exponent /:= 2
|
||||
base := base ^ 2 % modulus
|
||||
}
|
||||
return result
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue