ソースコード 拡げる

Copy
```#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
bool E[100001]={0};
vector<int> P;
for(int i=2;(long long)i*i*i<=10000000000ll;i++){
if(!E[i]){
for(int j=2*i;(long long)j*j*j<=10000000000ll;j+=i){
E[j]=1;
}
P.push_back(i);
}
}
int NP=P.size();
int n;
scanf("%d",&n);
static long long S[100000];
for(int i=0;i<n;i++){
scanf("%lld",S+i);
}
static long long s[100000];
for(int i=0;i<n;i++){
s[i]=1ll;
for(int j=0;j<NP&&(long long)P[j]*P[j]*P[j]<=S[i];j++){
int c=0;
while(S[i]%P[j]==0){
S[i]/=P[j];
c++;
}
if(c%3==1){
s[i]*=P[j];
}
else if(c%3==2){
s[i]*=P[j]*P[j];
}
}
s[i]*=S[i];
}
sort(s,s+n);
vector<pair<long long,int> > V;
for(int i=0;i<n;i++){
if(i==0||s[i-1]<s[i]){
V.push_back(make_pair(s[i],1));
}
else{
V[V.size()-1].second++;
}
}
int a=0;
for(int i=0;i<V.size();i++){
long long A=V[i].first,B=1ll;
if(A==1){
a++;
continue;
}
for(int j=0;j<NP&&(long long)P[j]*P[j]*P[j]<=A;j++){
int c=0;
while(A%P[j]==0){
A/=P[j];
c++;
}
if(c%3==1){
if(0<=B&&B<=10000000000ll){
B*=P[j]*P[j];
}
else{
B=-1;
}
}
else if(c%3==2){
if(0<=B&&B<=10000000000ll){
B*=P[j];
}
else{
B=-1;
}
}
}
long long t=(long long)(sqrt((double)A)+0.5);
if(t*t==A){
if(0<=B&&B<=10000000000ll){
B*=t;
}
else{
B=-1;
}
}
else{
if(0<=B&&A<=1000000ll){
B*=A*A;
}
else{
B=-1;
}
}
//printf("%lld %lld %lld\n",V[i].first,V[i].second,B);
int j=lower_bound(V.begin(),V.end(),make_pair(B,0))-V.begin();
if(j==V.size()||V[j].first>B){
a+=V[i].second;
}
else if(V[i].first<V[j].first){
a+=max(V[i].second,V[j].second);
}
}
printf("%d\n",a);
return 0;
}
```

#### 提出情報

提出日時 2016-08-21 21:58:28+0900 D - Anticube Huziwara C++14 (GCC 5.4.1) 1100 2050 Byte AC 622 ms 4088 KB

#### コンパイルエラー

```./Main.cpp: In function ‘int main()’:
./Main.cpp:21:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:24:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",S+i);
^
```

#### ジャッジ結果

セット名 Sample All

 AC × 3
 AC × 51
セット名 テストケース
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, s1.txt, s2.txt, s3.txt
ケース名 結果 実行時間 メモリ
01.txt AC 416 ms 4088 KB
02.txt AC 416 ms 4088 KB
03.txt AC 416 ms 4088 KB
04.txt AC 416 ms 4088 KB
05.txt AC 414 ms 4088 KB
06.txt AC 414 ms 4088 KB
07.txt AC 412 ms 4088 KB
08.txt AC 416 ms 4088 KB
09.txt AC 416 ms 4088 KB
10.txt AC 415 ms 4088 KB
11.txt AC 622 ms 2560 KB
12.txt AC 622 ms 2560 KB
13.txt AC 154 ms 3068 KB
14.txt AC 155 ms 3068 KB
15.txt AC 156 ms 3068 KB
16.txt AC 155 ms 3068 KB
17.txt AC 100 ms 1920 KB
18.txt AC 100 ms 1920 KB
19.txt AC 100 ms 1920 KB
20.txt AC 101 ms 1920 KB
21.txt AC 380 ms 3068 KB
22.txt AC 378 ms 3068 KB
23.txt AC 379 ms 3068 KB
24.txt AC 377 ms 3068 KB
25.txt AC 379 ms 3068 KB
26.txt AC 377 ms 3068 KB
27.txt AC 93 ms 4088 KB
28.txt AC 21 ms 1920 KB
29.txt AC 36 ms 1920 KB
30.txt AC 27 ms 1920 KB
31.txt AC 29 ms 1920 KB
32.txt AC 29 ms 1920 KB
33.txt AC 4 ms 384 KB
34.txt AC 105 ms 1920 KB
35.txt AC 97 ms 1920 KB
36.txt AC 4 ms 384 KB
37.txt AC 591 ms 3068 KB
38.txt AC 591 ms 3068 KB
39.txt AC 593 ms 3068 KB
40.txt AC 592 ms 3068 KB
41.txt AC 4 ms 384 KB
42.txt AC 4 ms 384 KB
43.txt AC 4 ms 384 KB
44.txt AC 4 ms 384 KB
45.txt AC 4 ms 384 KB
46.txt AC 4 ms 384 KB
47.txt AC 4 ms 384 KB
48.txt AC 4 ms 384 KB
s1.txt AC 4 ms 384 KB
s2.txt AC 4 ms 384 KB
s3.txt AC 4 ms 384 KB