結果

問題 No.300 平方数
ユーザー 保登心愛保登心愛
提出日時 2015-11-13 23:46:21
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 894 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 79,388 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 15:41:55
合計ジャッジ時間 2,035 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
vector<int> primeFactorization(ll n)
{
    vector<int> p;
    ll a = 2;
    while (n >= a * a) {
        if (n % a == 0) {
            p.push_back(a);
            n /= a;
        }
        else {
            a++;
        }
    }
    p.push_back(a);
    return p;
}
int main() {
    ll x, y = 1, n = 2;
    cin >> x;
    vector<int> p = primeFactorization(x);
    map<int, int> m;
    for (int i = 0; i < p.size(); i++) {
        m[p[i]]++;
    }
    for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
        if ((*it).second % 2 == 1) y *= (*it).first;
    }
    cout << y << endl;
    return 0;
}
0