結果

問題 No.300 平方数
ユーザー tubo28tubo28
提出日時 2015-11-14 00:08:18
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 13 ms / 1,000 ms
コード長 711 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 165,124 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-13 16:25:37
合計ジャッジ時間 3,099 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

pair<vector<ll>, vector<ll>> primeFactors(ll n){
    vector<ll> p,e;
    ll m = n;
    for(ll i = 2; i*i <= n; i++){
        if(m%i != 0) continue;
        int c = 0;
        while(m%i == 0) c++, m /= i;
        p.push_back(i); e.push_back(c);
    }
    if(m > 1){
        p.push_back(m); e.push_back(1);
    }
    return make_pair(p,e);
}

ll X;

ll solve(){
    vector<ll> p,e;
    tie(p,e) = primeFactors(X);
    ll res = 1;
    int k = p.size();
    for(int i = 0; i < k; i++){
        if(e[i]%2 == 1){
            res *= p[i];
        }
    }
    return res;
}

int main(){
    while(cin >> X){
        cout << solve() << endl;
    }
}
0