-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPP0131.cpp
97 lines (84 loc) · 1.75 KB
/
CPP0131.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define chk cout << "<< * checked * >>" << endl;
#define db cout << '<' << "i" << '=' << i << '>' << endl
using namespace std;
vector<long long> s(1000000, 0);
void sieve (long long n) {
s[0] = 1, s[1] = 1;
for (long long i=2; i<=n; i++){
if(s[i] == 0){
for (long long j=i+i; j<=n; j+=i) {
s[j] = 1;
}
}
}
}
long long checkNT(long long n){
if(n <= 1) return 0;
if(n <= 3) return 1;
if(n % 2 == 0 || n % 3 == 0) return 0;
for(long long i=2; i<=sqrt(n); i++){
if(n % i == 0) return 0;
}
return 1;
}
long long calSum(long long n){
long long m = n, sum = 0;
while (m != 0) {
sum += m%10;
m /= 10;
}
return sum;
}
long long BCNN(long long a, long long b){
return a*b / __gcd(a, b);
}
long long cal(long long x, long long a){
long long ans = x;
long long tmp = 0;
for(int i=0; i<=20; i++){
if(pow(10, i) > x){
tmp = i;
break;
}
}
a--;
while(a--){
ans = ans*pow(10, tmp)+x;
}
// cout << ans << endl;
return ans;
}
long long gcd(long long x,long long y){
if (y==0) return x;
return gcd(y,x%y);
}
void newSieve (long long n) {
s[0] = 1, s[1] = 1;
for (long long i=2; i<=n; i++){
if(s[i] == 0){
// s[i] = i;
for (long long j=i; j<=n; j+=i) {
if(!s[j]) s[j] = i;
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
newSieve(1000000);
while(t--){
long long n; cin >> n;
for(int i=1; i<=n; i++){
cout << s[i] << ' ';
}
cout << endl;
}
return 0;
}