結果

問題 No.2699 Simple Math (Returned)
ユーザー anago-pieanago-pie
提出日時 2024-04-06 00:34:05
言語 PHP
(8.3.4)
結果
AC  
実行時間 1,911 ms / 2,000 ms
コード長 716 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 32,540 KB
実行使用メモリ 32,540 KB
最終ジャッジ日時 2024-04-06 00:34:22
合計ジャッジ時間 16,675 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
32,540 KB
testcase_01 AC 419 ms
32,540 KB
testcase_02 AC 1,335 ms
32,540 KB
testcase_03 AC 423 ms
32,540 KB
testcase_04 AC 1,911 ms
32,540 KB
testcase_05 AC 1,150 ms
32,540 KB
testcase_06 AC 843 ms
32,540 KB
testcase_07 AC 1,589 ms
32,540 KB
testcase_08 AC 1,611 ms
32,540 KB
testcase_09 AC 1,617 ms
32,540 KB
testcase_10 AC 1,593 ms
32,540 KB
testcase_11 AC 1,591 ms
32,540 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
const mod = 998244353;

function modPower($x, $a)
{
    if ($a == 0) {
        return 1;
    } else if ($a % 2 == 0) {
        $k = modPower($x, $a / 2);
        $k %= mod;
        return($k * $k) % mod;
    } else {
        return(modPower($x, $a - 1) * $x) % mod;
    }
}
fscanf(STDIN, "%d", $T);

for($i=0; $i < $T;$i++){
    fscanf(STDIN, "%d %d", $N, $M);
    //N桁の9と1+0*(M-1)+1
    $N %= $M * 2;
    if($M>=$N){
        $ans=modPower(10, $N);
        $ans=($ans+mod-1)%mod;
    }
    else{
        $a = modPower(10, $M);
        $a=($a+mod-1)%mod;
        $b = modPower(10, $N - $M);
        $b = ($b + mod - 1) % mod;
        $ans = ($a + mod - $b) % mod;
    }
    
    printf($ans . "\n");
}
?>
0