結果

問題 No.847 Divisors of Power
ユーザー soysoy
提出日時 2019-08-12 16:30:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,156 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 77,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 10:19:07
合計ジャッジ時間 3,493 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 774 ms
5,376 KB
testcase_09 AC 8 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 35 ms
5,376 KB
testcase_17 AC 14 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1,156 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
vector<pair<long long int, long long int>> t;
int ans = 1;
long long int k, n, m;

int main() {
	void counting(long long int, int);
	void specialcount();
    int count=0;
	cin >> n >> k >> m;
	if (n == 1) {
		specialcount();
		return 0;
	}
	if (n % 2 == 0) {
		for (; n % 2 == 0; n /= 2) {
			count++;
		}
		t.push_back(make_pair(2, k * count));
	}
	for (long long int i = 3; n != 1; i += 2) {
		if (i > m) {
			t.push_back(make_pair(n,1));
			break;
		}
		if (n % i == 0) {
			for (count = 0; n % i == 0; n /= i) {
				count++;
			}
			t.push_back(make_pair(i, k * count));
		}
	}
	counting(0, 1);
	cout << ans;
	return 0;
}

void counting(long long int a, int px) {
	long long int x = px;
	if (a + 1 < size(t))
		counting(a + 1, x);
	for (int i = 0; i < t[a].second; i++) {
		x *= t[a].first;
		if (x > m) {
			return;
		}
		else {
			ans++;
			if (a + 1 < size(t)) {
				counting(a + 1, x);
			}
		}
	}
}
void specialcount() {
	if (m == 0)
		cout << 0;
	else
		cout << 1;
}
0