結果
| 問題 |
No.300 平方数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-13 23:36:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,481 bytes |
| コンパイル時間 | 585 ms |
| コンパイル使用メモリ | 54,648 KB |
| 最終ジャッジ日時 | 2024-11-14 19:27:30 |
| 合計ジャッジ時間 | 1,222 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘void Eratosthenes(ull*, ull)’:
main.cpp:26:23: error: ‘sqrt’ was not declared in this scope
26 | for(ull i = 2; i < sqrt((double)N); i++){
| ^~~~
main.cpp: In function ‘int main()’:
main.cpp:57:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
57 | scanf("%llu",&x);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
/* 入力開始! */
/* 入力終了! */
/* Eratosthenes(int prime[],int n)は
nまでの素数をprimeに、2,3,と入れていきます */
/* 実行後arr[i]はiが素数の時1になります */
ull arr[10000005];
void Eratosthenes(ull prime[],ull N){
for(ull i = 0; i < N; i++){
arr[i] = 1;
}
for(ull i = 2; i < sqrt((double)N); i++){
if(arr[i]){
for(ull j = 0; i * (j + 2) < N; j++){
arr[i *(j + 2)] = 0;
}
}
}
ull a = 0;
for(ull i = 2; i < N; i++){
if(arr[i]){
prime[a++] = i;
}
}
}
/* ull_pow(x,n)はx^nを返すよ! */
ull ull_pow(ull x,ull n) {
ull res = 1;
while(n > 0) {
if(n&1) res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
ull prime[10000000];
int main(void)
{
ull i,j,k,l;
ull x;
ull rep = 1;
scanf("%llu",&x);
Eratosthenes(prime,ull_pow(10,6)+10000);
for(i=0; x>1 && prime[i] < ull_pow(10,6);i++) {
if((x % prime[i]) == 0) {
int cnt = 1;
x /= prime[i];
while((x % prime[i]) == 0) {
cnt++;
x /= prime[i];
}
if(cnt % 2) rep *= prime[i];
}
}
rep *= x;
printf("%llu\n",rep);
return 0;
}