結果
| 問題 |
No.1063 ルートの計算 / Sqrt Calculation
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2020-05-29 21:21:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 746 bytes |
| コンパイル時間 | 2,759 ms |
| コンパイル使用メモリ | 198,532 KB |
| 最終ジャッジ日時 | 2025-01-10 16:21:25 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif
template <class T, class Op = multiplies<T>>
constexpr T power(T a, long long n, Op op = Op(), T e = {1}) {
assert(n >= 0);
while (n) {
if (n & 1) e = op(e, a);
if (n >>= 1) a = op(a, a);
}
return e;
}
template <class T> map<T, int> factorize(T n) {
map<T, int> res;
for (T i = 2; i * i <= n; ++i)
while (n % i == 0) ++res[i], n /= i;
if (n != 1) ++res[n];
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
int a = 1, b = 1;
for (auto [p, e] : factorize(n)) {
a *= power(p, e / 2);
b *= power(p, e & 1);
}
cout << a << ' ' << b << '\n';
}
risujiroh