-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime4.cpp
More file actions
45 lines (42 loc) · 904 Bytes
/
Copy pathPrime4.cpp
File metadata and controls
45 lines (42 loc) · 904 Bytes
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
#include<iostream>
int prime(int x){
bool check[x+1] = {true};
check[1] = false;
check[0] = false;
for (int i = 2; i * i <= x; i++)
{
if(check[i] == true){
for (int j = i*i; j <= x; j+=i)
{
check[j] = false;
}
}
}
}
int main(){
int t;
std::cin>>t;
while (t--)
{
int n;
std::cin>>n;
std::cout<<1<<" ";
for (int i = 2; i <= n; i++)
{
if(i%2 == 0){
std::cout<<2<<" ";
}
else
{
int j = 3;
while (i%j != 0)
{
j+=2;
if(j == i) break;
}
std::cout <<j<<" ";
}
}
std::cout<<std::endl;
}
}