結果
問題 |
No.3026 Range LCM (Online Version)
|
ユーザー |
![]() |
提出日時 | 2025-05-14 13:02:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,550 bytes |
コンパイル時間 | 652 ms |
コンパイル使用メモリ | 65,528 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-05-14 13:04:10 |
合計ジャッジ時間 | 4,798 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 36 |
ソースコード
#include <iostream> int main() { // Use long long to store the input number N, as N can be up to 10^9 - 1. long long n; // Read the input integer N from standard input. std::cin >> n; // Define the modulus M. Based on the problem context and examples, // the likely modulus is 10^9 + 7. We use long long for the modulus as well. long long m = 1000000007; // Calculate N^3 mod M. // We need to perform calculations using modular arithmetic to prevent overflow, // as N^3 can exceed the capacity of standard integer types. // Using long long ensures that intermediate products (like n*n or n*n*n before modulo) // fit within the 64-bit integer range (up to ~9 * 10^18). // Step 1: Calculate n % m. Since n is given as < 10^9 and m = 10^9 + 7, // n % m will simply be n if n is positive. However, doing the modulo // explicitly is good practice. long long n_mod_m = n % m; // Step 2: Calculate (n * n) % m. // The multiplication (n_mod_m * n_mod_m) is performed using long long. long long n_squared_mod_m = (n_mod_m * n_mod_m) % m; // Step 3: Calculate (n * n * n) % m by multiplying the result from Step 2 with n_mod_m. // The multiplication (n_squared_mod_m * n_mod_m) is performed using long long. long long n_cubed_mod_m = (n_squared_mod_m * n_mod_m) % m; // Output the final result (N^3 mod M) to standard output, followed by a newline. std::cout << n_cubed_mod_m << std::endl; // Return 0 to indicate successful execution. return 0; }