結果

問題 No.1287 えぬけー
ユーザー こまるこまる
提出日時 2020-11-14 12:05:40
言語 Haskell
(9.8.2)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 11,416 ms
コンパイル使用メモリ 199,996 KB
実行使用メモリ 18,460 KB
最終ジャッジ日時 2023-09-30 04:50:59
合計ジャッジ時間 13,671 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,852 KB
testcase_01 AC 3 ms
7,996 KB
testcase_02 AC 3 ms
7,916 KB
testcase_03 AC 2 ms
7,944 KB
testcase_04 AC 3 ms
7,992 KB
testcase_05 AC 222 ms
18,440 KB
testcase_06 AC 232 ms
18,460 KB
testcase_07 AC 232 ms
17,592 KB
testcase_08 AC 223 ms
18,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:31:24: warning: [GHC-68441] [-Wdeprecations]
    In the use of ‘powModInteger’
    (imported from GHC.Integer.GMP.Internals):
    Deprecated: "Use integerPowMod# instead"
   |
31 | powModInt a b m = fI $ GMP.powModInteger (fi a) (fi b) (fi m)
   |                        ^^^^^^^^^^^^^^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import           Control.Monad.ST
import           Control.Monad.State
import qualified Data.ByteString.Char8     as BSC8
import           Data.Char
import           Data.Coerce
import qualified Data.Vector.Unboxed       as VU
import qualified GHC.Integer.GMP.Internals as GMP

main :: IO ()
main = do
  t <- readLn :: IO Int
  xs <- parseN2 t
  putStr . unlines . map show . VU.toList $ solve xs

solve :: VU.Vector (Int, Int) -> VU.Vector Int
solve vec = runST $ do
  flip VU.mapM vec $ \v -> do
    let
      x = fst v
      k = snd v
      b = powModInt k 500000001 1000000006
    return $ powModInt x b 1000000007

fi :: Int -> Integer
fi = fromIntegral
{-# INLINE fi #-}
fI :: Integer -> Int
fI = fromInteger
{-# INLINE fI #-}
powModInt :: Int -> Int -> Int -> Int
powModInt a b m = fI $ GMP.powModInteger (fi a) (fi b) (fi m)
{-# INLINE powModInt #-}
type CParser a = StateT BSC8.ByteString Maybe a
runCParser :: CParser a -> BSC8.ByteString -> Maybe (a, BSC8.ByteString)
runCParser = runStateT
{-# INLINE runCParser #-}
int :: CParser Int
int = coerce $ BSC8.readInt . BSC8.dropWhile isSpace
{-# INLINE int #-}
parseN2 :: Int -> IO (VU.Vector (Int, Int))
parseN2 n = VU.unfoldrN n (runCParser $ (,) <$> int <*> int) <$> BSC8.getContents
{-# INLINE parseN2 #-}
0