-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUVA_294.cpp
70 lines (57 loc) · 1.83 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
66
67
68
69
70
#include <bits/stdc++.h>
using namespace std;
int main() {
int testcase;
scanf("%d",&testcase);
while(testcase--) {
long long low,up;
scanf("%lld %lld",&low,&up);
long long result,songkha;
long long highest = -1;
for ( long long i = low ; i <= up ; i++) {
vector <long long > primes;
long long y = i ;
long long z = i ;
// cout << y << " " << z << endl;
long long x = floor(sqrt(y))+1;
//cout << x << endl;
bool mark[x+5];
memset(mark,0,sizeof(mark));
for ( long long i = 4 ; i <= x ; i = i+2) mark[i] = 1 ;
mark[1] = 1 ;
mark[0] = 1 ;
mark[2] = 0 ;
for ( long long i = 3 ; i*i <= x ; i = i+2) {
if ( mark[i] == 0) {
for ( long long j = i*i ; j <= x ; j = j + i ) {
mark[j] = 1 ;
}
}
}
for ( long long i = 2 ; i <= x ; i++)
if ( mark[i] == 0) primes.push_back(i);
//for ( int i = 0 ; i < primes.size() ; i++) cout << primes[i] << " " ;
//cout << endl;
long long divisors = 1 ;
for ( long long i = 0 ; i < primes.size() ; i++) {
if ( y % primes[i] == 0) {
long long cnt = 1 ;
while( y % primes[i] == 0) {
y = y/primes[i];
cnt++;
}
divisors = divisors*cnt;
}
}
if ( y > 2) divisors = divisors*2;
//cout << divisors << endl;
if ( divisors > highest) {
result = z ;
songkha = divisors;
highest = divisors;
}
}
printf("Between %lld and %lld, %lld has a maximum of %lld divisors.\n",low,up,result,songkha);
}
return 0 ;
}