結果

問題 No.2576 LCM Pattern
ユーザー anago-pieanago-pie
提出日時 2023-12-13 21:07:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 1,615 ms
コンパイル使用メモリ 170,980 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-13 21:07:10
合計ジャッジ時間 2,906 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 1 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 3 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 AC 2 ms
6,548 KB
testcase_22 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'll power(ll, ll)':
main.cpp:45:1: warning: control reaches end of non-void function [-Wreturn-type]
   45 | }
      | ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define debug 0
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int MOD = 1000000007;
const double pi = atan2(0, -1);
#include <time.h>
#include <chrono>

void func(vector<ll> &exp, vector<ll> &prime, ll M) {
	for (ll i = 2; i <= sqrt(M); i++) {
		if (M % i == 0) {
			prime.push_back(i);
			ll c = 0;
			while (M % i == 0) {
				M /= i;
				c++;
			}
			exp.push_back(c);
		}
	}

	if (M > 1) {
		prime.push_back(M);
		exp.push_back(1);
	}
}

ll power(ll p, ll a) {
	if (a == 0) {
		return 1LL;
	}
	if (a % 2 == 1) {
		return (p * power(p, a - 1)) % mod;
	}
	if (a % 2 == 0) {
		ll t = power(p, a / 2) % mod;
		return (t * t)%mod;
	}
}

int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll> exp, prime;

	func(exp, prime, M);

	ll ans = 1;
	rep(i, prime.size()) {
		ans *= (mod + power(exp[i] + 1, N) - power(exp[i], N)) % mod;
		ans %= mod;
	}

	cout << ans << endl;
}
0