結果
問題 | No.300 平方数 |
ユーザー |
|
提出日時 | 2015-11-13 23:23:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 11 ms / 1,000 ms |
コード長 | 1,098 bytes |
コンパイル時間 | 630 ms |
コンパイル使用メモリ | 70,228 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-13 15:18:00 |
合計ジャッジ時間 | 2,088 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <iostream>#include <cstdio>#include <vector>#include <algorithm>#include <utility>#include <string>#include <cmath>using namespace std;vector<long long> getPrimes(long long n) {vector<bool> isPrime(n + 1, true);isPrime[0] = false;isPrime[1] = false;for (long long i = 2; i * i <= n; i++) {if (isPrime[i]) {for (long long j = 2 * i; j <= n; j += i) {isPrime[j] = false;}}}vector<long long> primes;for (long long i = 0; i <= n; i++) {if (isPrime[i]) {primes.emplace_back(i);}}return primes;}int main() {long long x;cin >> x;long long rt_x = sqrt(x);auto primes = getPrimes(rt_x);long long y = 1;int idx = 0;vector<long long> n_prime(primes.size(), 0);while (x > 1) {// printf("%lld %d %lld\n", x, idx, primes[idx]);if (idx >= primes.size()) {y *= x;break;}if (x % primes[idx] == 0) {n_prime[idx]++;x /= primes[idx];} else {idx++;}}for (int i = 0; i < n_prime.size(); i++) {if (n_prime[i] % 2 == 1) {y *= primes[i];}}cout << y << endl;return 0;}