Submission #00093


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x) setprecision(x)
vector<bool> IsPrime;
void sieve(size_t max){
if(max+1 > IsPrime.size()){ // resizeで要素数が減らないように
IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
}
IsPrime[0] = false; // 0は素数ではない
IsPrime[1] = false; // 1は素数ではない
for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
if(IsPrime[i]) // iが素数ならば
for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
IsPrime[i*j] = false; // 素数ではない
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n;
cin>>n;
int a;
sieve(6*10000000);
rep(i,n){
cin>>a;
if(IsPrime[a]){
cout<<1<<'\n';
}
else if(a==1){
cout<<2<<'\n';
}
else{
cout<<"NA"<<'\n';
}
}
return(0);
}

ステータス

項目 データ
問題 0005 - 掛けても素数!?
ユーザー名 ei1918
投稿日時 2020-04-25 22:17:57
言語 C++14
状態 Accepted
得点 300
ソースコード長 1577 Byte
最大実行時間 342 ms
最大メモリ使用量 48612 KB

セット

セット 得点 Cases
1 ALL 300 / 300 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.txt AC 196 ms 7900 KB
1
in02.txt AC 233 ms 7688 KB
1
in03.txt AC 214 ms 7732 KB
1
in04.txt AC 183 ms 7772 KB
1
in05.txt AC 203 ms 7816 KB
1
in06.txt AC 216 ms 8380 KB
1
in07.txt AC 290 ms 11236 KB
1
in08.txt AC 279 ms 13452 KB
1
in09.txt AC 291 ms 15800 KB
1
in10.txt AC 296 ms 18784 KB
1
in11.txt AC 304 ms 21640 KB
1
in12.txt AC 276 ms 24496 KB
1
in13.txt AC 284 ms 27352 KB
1
in14.txt AC 288 ms 30208 KB
1
in15.txt AC 304 ms 33072 KB
1
in16.txt AC 243 ms 34012 KB
1
in17.txt AC 342 ms 35852 KB
1
in18.txt AC 293 ms 37812 KB
1
in19.txt AC 294 ms 39776 KB
1
in20.txt AC 282 ms 42764 KB
1
in21.txt AC 302 ms 44732 KB
1
in22.txt AC 290 ms 46692 KB
1
in23.txt AC 307 ms 48532 KB
1
in24.txt AC 251 ms 48324 KB
1
in25.txt AC 227 ms 48380 KB
1
in26.txt AC 222 ms 48556 KB
1
sample01.txt AC 225 ms 48612 KB
1