結果

問題 No.129 お年玉(2)
ユーザー data9824data9824
提出日時 2015-05-28 00:27:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 304 ms / 5,000 ms
コード長 983 bytes
コンパイル時間 1,866 ms
コンパイル使用メモリ 64,732 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 17:10:52
合計ジャッジ時間 6,856 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 27 ms
4,376 KB
testcase_06 AC 193 ms
4,376 KB
testcase_07 AC 179 ms
4,376 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 164 ms
4,380 KB
testcase_10 AC 141 ms
4,380 KB
testcase_11 AC 166 ms
4,380 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 190 ms
4,376 KB
testcase_15 AC 158 ms
4,380 KB
testcase_16 AC 249 ms
4,376 KB
testcase_17 AC 117 ms
4,376 KB
testcase_18 AC 140 ms
4,380 KB
testcase_19 AC 34 ms
4,376 KB
testcase_20 AC 266 ms
4,376 KB
testcase_21 AC 140 ms
4,380 KB
testcase_22 AC 134 ms
4,376 KB
testcase_23 AC 191 ms
4,380 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 191 ms
4,376 KB
testcase_26 AC 68 ms
4,376 KB
testcase_27 AC 75 ms
4,376 KB
testcase_28 AC 304 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 34 ms
4,380 KB
testcase_39 AC 27 ms
4,380 KB
testcase_40 AC 77 ms
4,376 KB
testcase_41 AC 76 ms
4,380 KB
testcase_42 AC 29 ms
4,380 KB
testcase_43 AC 7 ms
4,376 KB
testcase_44 AC 50 ms
4,376 KB
testcase_45 AC 17 ms
4,376 KB
testcase_46 AC 8 ms
4,376 KB
testcase_47 AC 126 ms
4,376 KB
testcase_48 AC 21 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>

using namespace std;

static const long long MOD = 1000000000LL;

long long gcd(long long x, long long y) {
	do {
		if (x < y) {
			std::swap(x, y);
		}
		x = x % y;
	} while (x > 0LL);
	return y;
}

int main() {
	long long n, m;
	cin >> n >> m;
	long long win = n / 1000 % m;
	long long lose = m - win;
	vector<long long> numerators;
	for (long long i = max(win, lose) + 1; i <= m; ++i) {
		numerators.push_back(i);
	}
	for (long long i = min(win, lose); i >= 2; --i) {
		long long denominator = i;
		for (size_t k = 0; k < numerators.size() && denominator > 1; ++k) {
			long long divisor = gcd(numerators[k], denominator);
			if (divisor > 1) {
				numerators[k] /= divisor;
				denominator /= divisor;
			}
		}
		assert(denominator == 1);
	}
	long long result = 1;
	for (size_t i = 0; i < numerators.size(); ++i) {
		result *= numerators[i];
		result %= MOD;
	}
	cout << result << endl;
	return 0;
}
0