結果
問題 |
No.1063 ルートの計算 / Sqrt Calculation
|
ユーザー |
|
提出日時 | 2020-06-02 13:29:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,161 bytes |
コンパイル時間 | 1,719 ms |
コンパイル使用メモリ | 171,656 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-23 18:26:32 |
合計ジャッジ時間 | 2,133 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; inline int ctz(int n) { return __builtin_ctzl(n); } inline int ctz(long long n) { return __builtin_ctzll(n); } template<class T> vector<pair<T,int>> factorize(T n) { vector<pair<T,int>> factors; int c; if ((c = ctz(n)) > 0) { factors.emplace_back(2, c); n >>= c; } T lim = sqrt(n) + 0.1; for (T p = 3; p <= lim; p += 2) { c = 0; while (n % p == 0) { n /= p; c++; } if (c != 0) factors.emplace_back(p, c); } if (n != 1) factors.emplace_back(n, 1); return factors; } template <class INT_T> INT_T powi(INT_T b, INT_T x) { if (x == 0) return 1; if (x == 1) return b; if (x & 1) return powi(b*b, x/2) * b; return powi(b*b, x/2); } int main() { int n; cin >> n; vector<pair<int, int>> factors = factorize(n); int a = 1, b = 1; for (const auto& f : factors) { if (f.second / 2) { a *= powi(f.first, f.second/2); } if (f.second & 1) { b *= f.first; } } cout << a << " " << b << endl; }