結果

問題 No.982 Add
ユーザー bal4ubal4u
提出日時 2020-02-11 18:45:10
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 15:43:19
合計ジャッジ時間 1,463 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

int gcd(int a, int b) {
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

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

char f[10004];
int main()
{
    int A, B, x, y, N, n;
    int ans; 

    scanf("%d%d", &A, &B);
    if (gcd(A, B) > 1) puts("-1");
    else {
        N = lcm(A, B);
        for (x = 0; x <= N; ++x) for (y = 0; y <= N; ++y) {
            n = A*x + B*y;
            if (n < N) f[n] = 1;
        }
        ans = 0;
        for (x = 1; x < N; ++x) if (!f[x]) ++ans;
        printf("%d\n", ans);
    }
    return 0;
}
0