-
Notifications
You must be signed in to change notification settings - Fork 1
/
uva_294.cpp
66 lines (56 loc) · 1.3 KB
/
uva_294.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
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a, _b = b; i < _b; ++i)
#define FOR(i, a, b) for(int i = a, _b = b; i <= b; ++i)
#define FORD(i, a, b) for(int i = a, _b = b; i >= b; --i)
using namespace std;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef long long llong;
const int MX = 32023;
vector<int> primes;
bool isPrime[MX];
void sieve () {
memset(isPrime, true, sizeof isPrime);
REP(i, 2, MX) {
if(isPrime[i]) {
primes.push_back(i);
for(int j = i*i; j < MX; j += i) {
isPrime[j] = false;
}
}
}
}
int main() {
#ifndef Home
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
sieve();
int N;
scanf("%d", &N);
while(N--) {
int A, B;
scanf("%d %d", &A, &B);
int P, H = 0;
FOR(p, A, B) {
int n = p;
int divisors = 1;
for(int prime: primes) {
if(prime > n) break;
if(n%prime == 0) {
int cnt = 1;
while(n%prime == 0) n /= prime, cnt++;
divisors *= cnt;
}
}
if(H < divisors) {
H = divisors;
P = p;
}
}
printf("Between %d and %d, %d has a maximum of %d divisors.\n", A, B, P, H);
}
return 0;
}
// let N = p1^(e1)*p2^(e2)*...*pn^*(en) with pi is prime numbers, and ei is exp of pi
// => number divisors of N is k = (e1+1)(e2+1)...(en+1)