結果
問題 | No.1063 ルートの計算 / Sqrt Calculation |
ユーザー | hiroa |
提出日時 | 2020-05-29 21:34:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 873 bytes |
コンパイル時間 | 1,649 ms |
コンパイル使用メモリ | 171,024 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 02:40:46 |
合計ジャッジ時間 | 2,360 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=1000000007; #define INF 1LL<<30 #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() // 素因数分解 O(√n) // たとえば 60 = 2^2 x 3 x 5 だったら {(2, 2), (3, 1), (5, 1)} を返す // 素因数の個数はlogn vector<pair<ll,ll>> prime_factorize(ll n){ vector<pair<ll,ll>> res; for(ll p=2;p*p<=n;p++){ if(n%p!=0) continue; int num=0; // 指数 while(n%p==0){ num++; n/=p; } res.push_back({p,num}); } if(n!=1) res.push_back({n,1}); return res; } int main(){ int n; cin>>n; auto pf=prime_factorize(n); int a=1,b=1; for(auto p : pf){ a*=pow(p.first,p.second/2); b*=pow(p.first,p.second%2); } cout<<a<<" "<<b<<endl; }