結果

問題 No.251 大きな桁の復習問題(1)
ユーザー noriocnorioc
提出日時 2019-06-04 05:15:16
言語 D
(dmd 2.105.2)
結果
WA  
実行時間 -
コード長 1,014 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 93,180 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 01:31:31
合計ジャッジ時間 1,918 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 6 ms
4,384 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const MOD = 129402307;

long modulo(string s, long m) {
    long x = 0;
    foreach (d; s.map!(c => c - '0')) {
        x = (10 * x + d) % m;
    }
    return x;
}

long modPow(long x, long k, long m) {
    if (k == 0) return 1;
    if (k % 2 == 0) return modPow(x * x % m, k / 2, m);
    return x * modPow(x, k - 1, m) % m;
}

long calc(string s, string t) {
    long a = modulo(s, MOD);
    long b = modulo(t, MOD - 1);

    if (a == 0 && b == 0) return 1;
    if (a == 0) return 0;
    return modPow(a, b, MOD);
}

void main() {
    string s = read!string;
    string t = read!string;
    writeln(calc(s, t));
}
0