-
Notifications
You must be signed in to change notification settings - Fork 0
/
p38.cpp~
51 lines (48 loc) · 977 Bytes
/
p38.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
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
bool isPrime(long x)
{
if (x == 2)
return true;
if (x < 3 || x % 2 == 0)
return false;
float lim=sqrt(x);
for (long i = 3; i <= lim; i += 2)
if (x % i == 0)
return false;
return true;
}
bool isPan(long x, int n)
{
unsigned int d[n+2];
for (int i = 1; i <= n; i++)
d[i]=0;
int len = (int)log10(x)+1;
for (int i = 1; i <= n; i++)
{
int index = x % 10;
if (d[index] != 0)
return false;
d[index]++;
x /= 10;
}
return true;
}
int main()
{
long max = 0;
for (long i = 987654321; i >= 0; i-=2)
{
if (isPan(i,(int)log10(i)+1))
{
if (isPrime(i))
{
cout << i << endl;
return 0;
}
}
}
return 0;
}