結果

問題 No.373 かけ算と割った余り
ユーザー 👑 obakyanobakyan
提出日時 2019-03-30 19:34:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 459 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 56,036 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 05:55:39
合計ジャッジ時間 1,056 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdlib>

long modinv(long src, long mod)
{
    long num = mod - 2;
    long res = 1;
    while(0 < num){
        if(num % 2 == 1){
            res = (res * src) % mod;
            num--;
        }
        src = (src * src) % mod;
        num /= 2;
    }
    return res;
}

int main()
{
    long a, b, c, d;
    std::cin >> a >> b >> c >> d;
    a *= b; a %= d;
    a *= modinv(c, d); a %= d;
    std::cout << a << std::endl;
}

0