-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSPOJ3107.cc
More file actions
64 lines (58 loc) · 1.34 KB
/
SPOJ3107.cc
File metadata and controls
64 lines (58 loc) · 1.34 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
64
// SPOJ 3107: Odd Number of Divisors
// http://www.spoj.com/problems/ODDDIV/
//
// Solution: math, binary search
//
// x has odd number of divisors iff x is squared number.
// So, we first enumerate all squared number,
// bucket them by the number of divisors, and binary search.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <functional>
#include <algorithm>
#include <tr1/unordered_map>
using namespace std;
using namespace tr1;
#define ALL(c) c.begin(), c.end()
#define FOR(i,c) for(typeof(c.begin())i=c.begin();i!=c.end();++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define fst first
#define snd second
typedef long long LL;
unordered_map<int, vector<LL> > a;
// number of divisors of x*x
LL divisors(LL x) {
LL ans = 1;
for (LL y = 2; y*y <= x; ++y) {
if (x % y == 0) {
LL c = 0;
while (x % y == 0) {
x /= y;
++c;
}
ans *= (2*c+1);
}
}
if (x > 1) ans *= 3;
return ans;
}
void init() {
for (LL x = 1; x*x < 10000000000ll; ++x)
a[divisors(x)].push_back(x*x);
}
LL solve(int k, LL lo, LL hi) {
return upper_bound(ALL(a[k]), hi) - lower_bound(ALL(a[k]), lo);
}
int main() {
init();
int T; scanf("%d", &T);
while (T--) {
int k;
LL lo, hi;
scanf("%d %lld %lld", &k, &lo, &hi);
printf("%lld\n", solve(k, lo, hi));
}
}