forked from chr4ss1/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPCPC12J.cpp
More file actions
64 lines (50 loc) · 1.07 KB
/
PCPC12J.cpp
File metadata and controls
64 lines (50 loc) · 1.07 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
#include <stdio.h>
#include <utility>
#include <string.h>
#include <map>
#include <algorithm>
using namespace std;
typedef map<int, int> intmap;
typedef pair<int, int> intpair;
int ra()
{
int test;
scanf("%d", &test);
while(test--){
int i, lucky;
scanf("%d", &lucky);
i = lucky;
intmap lucky_divisors;
while(i--){
int d;
scanf("%d", &d);
if(lucky_divisors.find(d) == lucky_divisors.end())
lucky_divisors[d] = 0;
lucky_divisors[d] += 1;
}
// lucky=f
int best_freq = -1;
int best_divisor = -1;
for(intmap::iterator it = lucky_divisors.begin(); it != lucky_divisors.end(); it++){
int divisor = it->first;
int frequency = it->second;
if(divisor && frequency % divisor == 0){
if(best_freq == -1){
best_freq = frequency;
best_divisor = divisor;
continue;
}
if(best_freq == frequency && best_divisor > divisor){
best_divisor = divisor;
continue;
}
if(frequency > best_freq){
best_freq = frequency;
best_divisor = divisor;
}
}
}
printf("%d\n", best_divisor);
}
return 0;
}