結果
問題 |
No.2351 Butterfly in Summer
|
ユーザー |
|
提出日時 | 2023-06-16 23:06:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,152 bytes |
コンパイル時間 | 591 ms |
コンパイル使用メモリ | 64,324 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 16:10:28 |
合計ジャッジ時間 | 1,408 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 21 |
ソースコード
#include <iostream> #define int long long using namespace std; const int MOD = 998244353; // Function to calculate the modular inverse of 'a' modulo 'm' int modularInverse(int a, int m) { int m0 = m, t, q; int x0 = 0, x1 = 1; if (m == 1) return 0; // Apply extended Euclidean algorithm while (a > 1) { q = a / m; t = m; m = a % m, a = t; t = x0; x0 = x1 - q * x0; x1 = t; } // Make sure x1 is positive if (x1 < 0) x1 += m0; return x1; } // Function to calculate ((n * k) / k^n) % 998244353 int calculateExpression(int n, int k) { int numerator = (n * k) % MOD; int denominator = modularInverse(k, MOD); int exponent = n; // Calculate numerator * denominator^exponent modulo MOD int result = numerator; while (exponent > 0) { result = (result * denominator) % MOD; exponent--; } return result; } int32_t main() { int n, k; cout << "Enter the values of n and k: "; cin >> n >> k; int result = calculateExpression(n, k); cout << "Result: " << result << endl; return 0; }