結果

問題 No.300 平方数
ユーザー kuisibakuisiba
提出日時 2016-10-28 17:17:38
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 879 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 60,796 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-03 07:17:01
合計ジャッジ時間 3,773 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 RE -
testcase_16 AC 2 ms
5,376 KB
testcase_17 RE -
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

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