結果

問題 No.300 平方数
ユーザー kuisiba
提出日時 2016-10-28 17:17:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 879 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 61,784 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-11-24 05:13:00
合計ジャッジ時間 40,044 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 RE * 2 TLE * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int64_t n;
  cin >> n;
  if (n == 1) {
    cout << "1" << endl;
    return 0;
  }
  int evencount = 0;
  if (!(n & 1)) {
    while (!(n & 1)) {
      n >>= 1;
      evencount++;
    }
  }
  if (n == 1) {
    if (evencount & 1) {
      cout << "2" << endl;
    } else {
      cout << "1" << endl;
    }
    return 0;
  }
  vector<int> v;
  if (evencount & 1) {
    v.push_back(2);
  }
  int oddcount = 0;
  for (int i = 3; i <= n; i += 2) {
    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
        oddcount++;
      }
      if (oddcount & 1) {
        v.push_back(i);
      }
    }
    oddcount = 0;
  }
  int64_t ans = v.at(0);
  for (int i = 1; i < (int)v.size(); i++) {
    ans *= v.at(i);
  }
  cout << ans << endl;
}
0