結果

問題 No.300 平方数
ユーザー nenuon
提出日時 2017-07-08 00:03:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 91 ms / 1,000 ms
コード長 1,094 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 91,296 KB
実行使用メモリ 21,492 KB
最終ジャッジ日時 2024-10-06 10:10:05
合計ジャッジ時間 6,198 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

const ll MAX = 10000007;
bool isPrime[MAX];
vector<ll> prime;
void makePrime(){
  for (ll i = 0; i < MAX; i++){
    isPrime[i] = true;
  }
  isPrime[0] = isPrime[1] = false;
  for (ll i = 2; i * i < MAX + 1; i++){
    if(isPrime[i]){
      for (ll j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  FOR(i,0,MAX){
    if(isPrime[i]) prime.push_back(i);
  }
  return;
}
int main(){
  ll x; cin >> x;
  ll y = 1;
  makePrime();
  int p = 0;
  ll xx = x;
  int j = 10000;
  while(j > 0){
    int cnt = 0;
    while(xx % prime[p] == 0){
      xx /= prime[p];
      cnt++;
    }
    if(cnt % 2 == 1) y *= prime[p];
    p++;
    j--;
    if(xx == 1) break;
  }
  if(xx > 1){
    y *= xx;
  }
  printf("%lld\n", y);
  return 0;
}
0