結果

問題 No.300 平方数
ユーザー nCk_cv
提出日時 2015-12-08 16:03:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 14 ms / 1,000 ms
コード長 695 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 20:12:18
合計ジャッジ時間 2,306 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define ll long long

int main() {
  ll X;
  cin >> X;
  std::vector<ll> v;
  std::map<ll, ll> m;
  for(ll i = 2; i <= sqrt(X)+1; i++) {
    while(X % i == 0) {
      X /= i;
      if(m.find(i) == m.end()) {
        m[i] = 1;
        v.push_back(i);
      }
      else {
        m[i]++;
      }
    }
  }
  if(m.find(X) == m.end()) {
    m[X] = 1;
    v.push_back(X);
  }
  else {
    m[X]++;
  }
  ll ans = 1;
  for(int i = 0; i < v.size(); i++) {
    if(m[v.at(i)] % 2 == 1)
    ans *= v.at(i);
  }
  cout << ans << endl;


}
0