blob: 7a027fcc8a5ae89868581dd40632da6125431bee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE MagicHash #-}
module Main (main) where
import Data.List (group)
import Data.Bits
import Data.Word
import Control.Monad
import GHC.Word
import GHC.Base
import GHC.Num.Natural
import GHC.Num.Integer
integerPowMod :: Integer -> Integer -> Integer -> Maybe Integer
integerPowMod b e m = case integerPowMod# b e (fromIntegral m) of
(# | () #) -> Nothing
(# r | #) -> Just (fromIntegral r)
main :: IO ()
main = do
print $ naturalPowMod b e m
print $ naturalPowMod b e (m-1)
print $ integerPowMod b e m
print $ integerPowMod b e (m-1)
print $ integerPowMod b (-e) m
print $ integerPowMod b (-e) (m-1)
print $ integerPowMod (-b) e m
print $ integerPowMod (-b) e (m-1)
print $ integerPowMod (-b) (-e) m
print $ integerPowMod (-b) (-e) (m-1)
where
b,e,m :: Num a => a
b = 2988348162058574136915891421498819466320163312926952423791023078876139
e = 2351399303373464486466122544523690094744975233415544072992656881240319
m = 10^(40::Int)
|