結果
問題 |
No.129 お年玉(2)
|
ユーザー |
![]() |
提出日時 | 2015-01-24 01:39:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2,121 ms / 5,000 ms |
コード長 | 690 bytes |
コンパイル時間 | 474 ms |
コンパイル使用メモリ | 60,120 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-27 23:37:53 |
合計ジャッジ時間 | 24,766 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#include <iostream> #include <algorithm> #include <sstream> #include <cstdio> using namespace std; #define MOD 1000000000LL typedef long long LL; LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } int main(int argc, char *argv[]) { string s; getline(cin, s); LL N, M; stringstream ss(s); ss >> N; getline(cin, s); M = atoi(s.c_str()); N /= 1000; N %= M; LL a[10000] = {}; for (LL i = 0; i < N; ++i) { a[i] = M - N + i + 1; } for (LL i = 1; i <= N; ++i) { LL b = i; for (LL j = 0; b > 1 && j < N; ++j) { LL g = gcd(a[j], b); a[j] /= g, b /= g; } } LL ans = 1; for (LL i = 0; i < N; ++i) { ans = (ans * a[i]) % MOD; } cout << ans << endl; return 0; }