-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path294.cpp
87 lines (62 loc) · 1.42 KB
/
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<bits/stdc++.h>
using namespace std;
vector<int> generate(void){
int count = 31623;
int temp;
bool prime;
vector<int> primes;
primes.push_back(2);
for(int i = 2; i < count; i++)
{
temp = ceil(sqrt(i))+1;
prime = true;
for(int j = 2; j < temp; j++)
{
if(i % j == 0){
prime = false;
break;
}
}
if(prime){
primes.push_back(i);
}
}
return primes;
}
int reduce(unsigned int &value, int f){
int times = 0;
while(value%f == 0){
value /= f;
times++;
}
return times;
}
int main(){
unsigned int number,L,U,max_name, i;
int N;
int j;
int count, temp, max;
vector<int> primes = generate();
scanf("%d", &N);
while(N--){
scanf("%u %u",&L,&U);
max = 0;
for(i = L; i <= U; i++)
{
temp = 1;
number = i;
for(auto f : primes){
temp *= (reduce(number, f) +1);
if(number == 1){
break;
}
}
if(max < temp){
max = temp;
max_name = i;
}
}
printf("Between %u and %u, %u has a maximum of %d divisors.\n", L,U,max_name,max);
}
return 0;
}