-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10789-Prime Frequency.cpp
executable file
·102 lines (86 loc) · 1.85 KB
/
10789-Prime Frequency.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
98
99
100
101
102
#include <iostream>
#include <bitset>
#include <vector>
#include <cmath>
#include <map>
#include <cstring>
using namespace std;
bitset<10000005> b;
long long SSize;
vector<int> prime;
map<char ,int> m;
map <int , char> rm;
int T ;
int rep[62] = {0};
vector<char> nums;
void sieve(long long upper)
{
SSize = upper;
b.set();
b[0]=b[1]= 0;
for (long long i = 2 ; i <= SSize ;i++ )
{
if(b[i])
{
for ( long long j = i * i ; j <= SSize ; j+= i)
b[j] = 0;
prime.push_back((int)i);
}
}
}
bool isPrime(long long n)
{
if (n <= SSize)
return b[n];
for ( int i = 0 ; i < prime.size() ; i++)
{
if ( n % prime[i] == 0)
return false;
}
return true;
}
int main ()
{
sieve(2001);
int x = 0;
for (int i = 0;i < 10 ; i++, x++)
{
m[(char)('0'+i)] = x;
rm[x] = (char)('0'+i);
}
for (int i = 0;i < 26 ;i++, x++ )
{
m[(char)( 'A'+ i)] = x;
rm[x] = (char)( 'A'+ i);
}
for (int i = 0;i < 26 ;i++ , x++)
{
m[(char)( 'a'+ i)] = x;
rm[x] = (char)( 'a'+ i);
}
cin >> T;
for (int k = 1;k <= T ;k++ )
{
nums.clear();
for (int i = 0;i < 62 ;i++ )
{
rep[i] = 0;
}
string s;
cin >> s;
for (int i = 0 ; i < s.length() ; i++)
rep[m[s[i]]]++;
for (int i = 0 ;i < 62 ;i++ )
if (isPrime(rep[i]))
nums.push_back(rm[i]);
cout << "Case "<< k<< ": ";
for (int i = 0 ;i < nums.size() ;i++ )
{
cout<<nums[i];
}
if(nums.size() == 0)
cout << "empty";
cout << endl;
}
return 0;
}