結果

問題 No.186 中華風 (Easy)
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-12-27 17:58:43
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,215 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 149,216 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 00:15:05
合計ジャッジ時間 2,918 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/dmd2/linux/bin64/../../src/phobos/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`

ソースコード

diff #

import std.algorithm;
import std.bigint;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

long extgcd(long a, long b, ref long x, ref long y) {
    long g = a; x = 1; y = 0;
    if (b != 0) {
        g = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    return g;
}

T lcm(T)(T a, T b) {
    return a / gcd(a, b) * b;
}

void main() {
    auto X = new long[3], Y = new long[3];
    foreach (i; 0 .. 3) readf("%s %s\n", &X[i], &Y[i]);

    long g = gcd(Y[0], Y[1]);
    if (abs(X[0] - X[1]) % g != 0) {
        writeln(-1);
        return;
    }
    long p, q; extgcd(Y[0], Y[1], p, q);
    long n = (X[0] * q * Y[1] + X[1] * p * Y[0]) / g;
    long y1 = lcm(Y[0], Y[1]);
    long x1 = n % y1;
    extgcd(Y[2], y1, p, q);
    g = gcd(Y[2], y1);
    if (abs(X[2] - x1) % g != 0) {
        writeln(-1);
        return;
    }
    BigInt t = (BigInt(y1) / g * X[2] * q + BigInt(Y[2]) / g * x1 * p);
    auto l = lcm(y1, Y[2]);
    writeln(t % l > 0 ? t % l : t % l + l);
}
0