結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー _lambda00_lambda00
提出日時 2020-06-11 22:10:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,798 bytes
コンパイル時間 1,174 ms
コンパイル使用メモリ 123,284 KB
実行使用メモリ 73,192 KB
最終ジャッジ日時 2023-09-06 08:39:37
合計ジャッジ時間 5,179 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <limits>

using ld = long double;
using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	/* constant */
	constexpr double epsilon = std::numeric_limits<double>::epsilon();

	/* math */
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	ul inline digit(const ul &num){ return static_cast<ul>(std::log10(num+epsilon))+1; }

	/* algorithm */
	ul gcd(const ul &a,const ul &b) { return (!b) ? a : gcd(b,a%b); } // NOTE: a > b
	std::vector<bool> eratosthenes(const ul &n)
	{
		std::vector<bool> prime_candidate(n,true);
		prime_candidate[0] = prime_candidate[1] = false;
		const ul max_n = static_cast<ul>(std::sqrt(n));
		for(ul i = 2;i <= max_n;++i)
		{
			if(!prime_candidate[i]) continue;
			for(ul j = 2;i*j < n;++j)
			{
				prime_candidate[i*j] = false;
			}
		}
		return prime_candidate;
	}

	/* string */
	inline ul same_char_count(const std::string s,const char &ch){ return std::count(std::cbegin(s),std::cend(s),ch); }
}

// std::cout << std::fixed << std::setprecision(15) << std::endl;

int main(int argc,char *argv[])
{
	ll n;
	std::cin >> n;

	auto prime = lamlib::eratosthenes(n);

	const ll loop = n+1;
	std::map<ll,ll> mp;
	for(int i = 0;i < loop;++i)
	{
		if(prime[i])
		{
			if(n%i == 0)
			{
				n /= i;
				++mp[i];
				--i;
			}
		}
	}
	
	ll ans_l = 1, ans_r = 1;
	for(auto itr = mp.begin();itr != mp.end();++itr)
	{
		ll count = itr->second;
		if(itr->second > 1)
		{
			ans_l *= std::pow(itr->first,count/2);
			count %= 2;
		}
		ans_r *= std::pow(itr->first,count);
	}

	std::cout << ans_l << " " << ans_r << std::endl;

	return 0;
}
0