forked from Badhansen/UVa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10852 - Less Prime.cpp
More file actions
179 lines (135 loc) · 4.46 KB
/
10852 - Less Prime.cpp
File metadata and controls
179 lines (135 loc) · 4.46 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
using namespace std;
#define filein() freopen("in.txt", "r", stdin)
#define fileout() freopen("out.txt", "w", stdout)
#define FIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define nfound(v, n) find(all(v), n)==v.end()
#define found(v, n) find(all(v), n)!=v.end()
#define UB(v, n) upper_bound(all(v), n)-v.begin()
#define LB(v, n) lower_bound(all(v), n)-v.begin()
#define on(n, p) (n | (1<<(p)))
#define off(n, p) (n & ~(1<<(p)))
#define check(n, p) (bool)(n & (1<<(p)))
#define MS(x, v) memset(&x, v, sizeof(x))
#define CL(x) memset(&x, 0, sizeof(x))
#define mp make_pair
#define pb push_back
#define p push
#define sz size
#define cl clear
#define po pop
#define em emplty
#define ss second
#define fi first
#define sf scanf
#define pf printf
#define pf1(n) pf("%d", n)
#define sc1(n) sf("%d", &n)
#define scl1(n) sf("%I64d", &n)
#define sc2(n, m) sf("%d %d", &n, &m)
#define scl2(n, m) sf("%I64d %I64d", &n, &m)
#define sc3(n, m, v) sf("%d %d %d", &n, &m, &v)
#define scl3(n, m, v) sf("%I64d %I64d %I64d", &n, &m, &v)
#define nl() pf("\n")
#define endl '\n'
#define Iterator(s) for(typeof(s.begin()) it=s.begin(); it!=s.end(); it++)
#define FOR(i, k, n) for(i=k; i<=n; i++)
#define For(i, k, n) for(i=k; i<n; i++)
#define ROF(i, n) for(i=n; i>=0; i--)
#define REP(i, n) for(i=0; i<n; i++)
#define Max(x, y) ((x)>(y) ? (x) : (y))
#define Min(x, y) ((x)<(y) ? (x) : (y))
#define Abs(x) ((x)<0 ? (-(x)): (x))
#define PI acos(-1.0)
#define EPS 1e-9
#define MAX 2e18
#define MOD 1000000007
typedef long long i64;
typedef unsigned long long ui64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;
template<class T> inline void IO(T &x){char c=getchar();T sgn=1;while(c<'0' || c>'9'){if (c=='-') sgn=-1;c=getchar();}x=0;while(c>='0' && c<='9'){x=(T)(x<<1)+(x<<3)+c-'0';c=getchar();}x*=sgn;}
template<class T> T POW(T b, T p){T res=1;while(p>0){if (p&1) res*=b;p >>= (1ll), b*=b;}return res;}
template<class T> T bMOD(T a, T p, T m){if (p==0) return (T) 1;if (!(p&1)){T temp=bMOD(a, p/2, m);return ((temp%m)*(temp%m))%m;}return ((a%m)*(bMOD(a, p-1, m)%m))%m;}
template<class T> T inMOD(T a, T m){return bMOD(a, m-2, m);}
template<class T> bool isPrime(T n){for(T i=2; i*i<=n; i++){if (n%i==0) return false;}return true;}
template<class T> string toString(T n){stringstream ss;string num;ss<<n;ss>>num;return num;}
template<class T> T sq(T n){return (n*n);}
template<class T> T gcd(T a, T b){return (b==0) ? a : gcd (b, a%b);}
template<class T> T lcm(T a, T b){return (a/gcd (a, b))*b;}
bool iseq(double a, double b){return fabs(a-b)<EPS;}
template<class T> T toDeg(T x){return (180.0*x)/((T)PI);}
template<class T> T toReg(T x){return (x*(T)PI)/(180.0);}
template<class T> double _distance (T x1, T y1, T x2, T y2){return 1.0*sqrt(sq(x1-x2)+sq(y1-y2));}
int kx[]={-2, -2, +2, +2, +1, -1, +1, -1};
int ky[]={+1, -1, +1, -1, -2, -2, +2, +2};
int dx[]={+0, +0, -1, +1, +1, +1, -1, -1};
int dy[]={+1, -1, +0, +0, -1, +1, +1, -1};
int x[]={+0, +0, +1, -1};
int y[]={+1, -1, +0, +0};
/*
@author: Badhan Sen
CSE, JUST.
mail: galaxybd9@gmail.com
*/
#define MM 100000
bool dp[MM+1];
void seive ()
{
memset(dp, false, sizeof dp);
int i, j, k=0;
for (i=4; i<=MM; i+=2){
dp[i]=true;
}
dp[0]=true;
dp[1]=true;
for (i=3; i*i<=MM; i+=2){
if (dp[i]==false){
for (j=i*i; j<=MM; j+=(i+i)){
dp[j]=true;
}
}
}
}
int main ()
{
seive();
int m, n;
cin >> m;
while(m--){
cin >> n;
int i=n/2;
for(i; i<n; i++){
if(dp[i]==false){
if(i<n && 2*i>n){
cout << i << endl;
break;
}
}
}
}
return 0;
}