Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
|
|
@ -19,4 +19,6 @@ You will use <math>13</math> as the congruence modulus and you will compute <mat
|
|||
It is important that the function <math>f</math> is agnostic about whether or not its argument is modular; it should behave the same way with normal and modular integers.
|
||||
In other words, the function is an algebraic expression that could be used with any ring, not just integers.
|
||||
<br><br>
|
||||
|
||||
;Related tasks:
|
||||
[[Modular exponentiation]]
|
||||
<br><br>
|
||||
|
|
|
|||
50
Task/Modular-arithmetic/FreeBASIC/modular-arithmetic.basic
Normal file
50
Task/Modular-arithmetic/FreeBASIC/modular-arithmetic.basic
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
Type ModInt
|
||||
As Ulongint Value
|
||||
As Ulongint Modulo
|
||||
End Type
|
||||
|
||||
Function Add_(lhs As ModInt, rhs As ModInt) As ModInt
|
||||
If lhs.Modulo <> rhs.Modulo Then Print "Cannot add rings with different modulus": End
|
||||
Dim res As ModInt
|
||||
res.Value = (lhs.Value + rhs.Value) Mod lhs.Modulo
|
||||
res.Modulo = lhs.Modulo
|
||||
Return res
|
||||
End Function
|
||||
|
||||
Function Multiply(lhs As ModInt, rhs As ModInt) As ModInt
|
||||
If lhs.Modulo <> rhs.Modulo Then Print "Cannot multiply rings with different modulus": End
|
||||
Dim res As ModInt
|
||||
res.Value = (lhs.Value * rhs.Value) Mod lhs.Modulo
|
||||
res.Modulo = lhs.Modulo
|
||||
Return res
|
||||
End Function
|
||||
|
||||
Function One(self As ModInt) As ModInt
|
||||
Dim res As ModInt
|
||||
res.Value = 1
|
||||
res.Modulo = self.Modulo
|
||||
Return res
|
||||
End Function
|
||||
|
||||
Function Power(self As ModInt, p As Ulongint) As ModInt
|
||||
If p < 0 Then Print "p must be zero or greater": End
|
||||
Dim pp As Ulongint = p
|
||||
Dim pwr As ModInt = One(self)
|
||||
While pp > 0
|
||||
pp -= 1
|
||||
pwr = Multiply(pwr, self)
|
||||
Wend
|
||||
Return pwr
|
||||
End Function
|
||||
|
||||
Function F(x As ModInt) As ModInt
|
||||
Return Add_(Power(x, 100), Add_(x, One(x)))
|
||||
End Function
|
||||
|
||||
Dim x As ModInt
|
||||
x.Value = 10
|
||||
x.Modulo = 13
|
||||
Dim y As ModInt = F(x)
|
||||
Print Using "x ^ 100 + x + 1 for x = ModInt(&, &) is ModInt(&, &)"; x.Value; x.Modulo; y.Value; y.Modulo
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue