結果

問題 No.1022 Power Equation
ユーザー square1001square1001
提出日時 2020-04-10 21:38:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 69,888 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 23:40:46
合計ジャッジ時間 1,164 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 3 ms
4,352 KB
testcase_02 AC 3 ms
4,352 KB
testcase_03 AC 5 ms
4,352 KB
testcase_04 AC 9 ms
4,348 KB
testcase_05 AC 11 ms
4,348 KB
testcase_06 AC 11 ms
4,348 KB
testcase_07 AC 10 ms
4,352 KB
testcase_08 AC 8 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
// Exactly same as TopCoder SRM 713 Div1 Easy - PowerEquation
int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int Q;
	cin >> Q;
	while (Q--) {
		int n;
		cin >> n;
		long long ret = 1LL * (2 * n - 1) * n;
		for (int i = 1; i <= 32; i++) {
			for (int j = 1; j <= 32; j++) {
				if (i + j == 2 || gcd(i, j) != 1) continue;
				int sum = 0, p = max(i, j);
				for (int k = 2; ; k++) {
					long long prod = 1;
					for (int l = 0; l < p; l++) prod *= k;
					if (prod > n) break;
					sum++;
				}
				ret = (ret + 1LL * sum * (n / p));
			}
		}
		cout << ret << endl;
	}
	return 0;
}
0