-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLove Letters!.cpp
67 lines (57 loc) · 1.12 KB
/
Love Letters!.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 100000
vector<bool> v (mx+1, true);
vector<int> primes;
void sieve()
{
v[0]=v[1] = false;
for(ll i=2; i<=mx; i++)
{
if(v[i])
{
primes.push_back(i);
for(ll j=i*i; j<=mx; j += i)
{
v[j] = false;
}
}
}
}
//Driver code
int main(void)
{
int tc, test=1;
cin >> tc;
map<char, int> mp;
sieve();
while(tc--)
{
ll n;
cin >> n;
string str = "";
for(ll i=0; i<n; i++)
{
char c ;
cin >> c;
mp[c]++;
}
cout << "Case " << test++ << ":" << endl;
int got = 0;
for(const auto &entry:mp)
{
if(binary_search(primes.begin(), primes.end(), entry.second))
{
cout << entry.first << " = " << entry.second << endl;
got = 1;
}
}
if(!got)
{
cout << "Love is painful !" << endl;
}
mp.clear();
}
return 0;
}