結果

問題 No.2260 Adic Sum
ユーザー startcppstartcpp
提出日時 2023-04-15 17:19:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 76,844 KB
実行使用メモリ 9,396 KB
最終ジャッジ日時 2024-04-19 10:45:12
合計ジャッジ時間 4,722 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 23 ms
5,376 KB
testcase_15 AC 32 ms
6,076 KB
testcase_16 AC 19 ms
5,376 KB
testcase_17 AC 35 ms
6,260 KB
testcase_18 AC 204 ms
9,244 KB
testcase_19 AC 223 ms
9,300 KB
testcase_20 AC 156 ms
9,276 KB
testcase_21 AC 160 ms
9,288 KB
testcase_22 AC 141 ms
9,396 KB
testcase_23 AC 99 ms
8,840 KB
testcase_24 AC 207 ms
9,304 KB
testcase_25 AC 55 ms
8,668 KB
testcase_26 AC 56 ms
8,656 KB
testcase_27 AC 61 ms
8,832 KB
testcase_28 AC 56 ms
8,668 KB
testcase_29 AC 57 ms
8,672 KB
testcase_30 AC 48 ms
6,420 KB
testcase_31 AC 99 ms
6,868 KB
testcase_32 AC 97 ms
6,868 KB
testcase_33 AC 49 ms
8,852 KB
testcase_34 AC 88 ms
9,228 KB
testcase_35 AC 333 ms
9,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <unordered_map>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, p;
int a[100000];

//modは素数pの累乗
int solve(int mod) {
	unordered_map<int, int> mp;
	int i;
	rep(i, n) mp[a[i] % mod]++;

	int ret = 0;
	for (unordered_map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {
		int cnt = it->second;
		ret += cnt * (cnt - 1) / 2;
	}
	return ret;
}

signed main() {
	int i;

	cin >> n >> p;
	rep(i, n) cin >> a[i];

	int mul = p;
	int ans = 0;
	while (mul <= 1000000000) {
		ans += solve(mul);
		mul *= p;
	}

	cout << ans << endl;
	return 0;
}
0