-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPP0108.cpp
More file actions
54 lines (49 loc) · 972 Bytes
/
CPP0108.cpp
File metadata and controls
54 lines (49 loc) · 972 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
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10000001
#define ll long long
using namespace std;
bool tang(int n) {
int last = n % 10;
n /= 10;
while (n) {
if (n % 10 >= last)
return 0;
last = n % 10;
n /= 10;
}
return 1;
}
bool giam(int n) {
int last = n % 10;
n /= 10;
while (n) {
if (n % 10 <= last)
return 0;
last = n % 10;
n /= 10;
}
return 1;
}
bool nt(int n) {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return 0;
}
return n > 1;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int cnt = 0;
for (int i = pow(10, n - 1) + 1; i < pow(10, n); i += 2) {
if ((tang(i) || giam(i)) && nt(i))
++cnt;
}
cout << cnt << endl;
}
return 0;
}