結果

問題 No.300 平方数
ユーザー CELICA
提出日時 2020-10-20 22:04:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 1,000 ms
コード長 640 bytes
コンパイル時間 1,344 ms
コンパイル使用メモリ 169,560 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-21 08:31:31
合計ジャッジ時間 2,534 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;

void primeFactorize(ll n, vector<pair<ll, ll> >& pf)
{
	for (ll a = 2; a * a <= n; ++a)
	{
		if (n % a != 0)
			continue;
		ll ex = 0;

		while (n % a == 0)
		{
			++ex;
			n /= a;
		}

		pf.push_back({ a, ex });
	}

	if (n != 1)
		pf.push_back({ n, 1 });
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll x;
	cin >> x;

	vector<pair<ll, ll> > pf;
	primeFactorize(x, pf);
	
	ll res{ 1 };
	for (const auto& it : pf)
		if (it.second & 1)
			res *= it.first;
	cout << res << "\n";

	return 0;
}
0