結果

問題 No.300 平方数
ユーザー masamasa
提出日時 2015-11-13 23:20:58
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,091 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 71,168 KB
実行使用メモリ 4,808 KB
最終ジャッジ日時 2023-10-11 16:34:48
合計ジャッジ時間 5,660 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 7 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,356 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 RE -
testcase_14 AC 2 ms
4,476 KB
testcase_15 AC 5 ms
4,352 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 10 ms
4,576 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 5 ms
4,352 KB
testcase_20 RE -
testcase_21 AC 9 ms
4,396 KB
testcase_22 AC 8 ms
4,456 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 AC 7 ms
4,352 KB
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 6 ms
4,352 KB
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>

using namespace std;

vector<long long> getPrimes(long long n) {
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = false;
	isPrime[1] = false;

	for (long long i = 2; i * i <= n; i++) {
		if (isPrime[i]) {
			for (long long j = 2 * i; j <= n; j += i) {
				isPrime[j] = false;
			}
		}
	}

	vector<long long> primes;
	for (long long i = 0; i <= n; i++) {
		if (isPrime[i]) {
			primes.emplace_back(i);
		}
	}

	return primes;
}

int main() {
	long long x;

	cin >> x;

	long long rt_x = sqrt(x);

	auto primes = getPrimes(rt_x);

	long long y = 1;

	int idx = 0;
	vector<long long> n_prime(primes.size(), 0);
	while (x > 1) {
// printf("%lld %d %lld\n", x, idx, primes[idx]);
		if (x < primes[idx]) {
			y *= x;
			break;
		}
		if (x % primes[idx] == 0) {
			n_prime[idx]++;
			x /= primes[idx];
		} else {
			idx++;
		}
	}

	for (int i = 0; i < n_prime.size(); i++) {
		if (n_prime[i] % 2 == 1) {
			y *= primes[i];
		}
	}

	cout << y << endl;

	return 0;
}
0