-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_Count_Good_Numbers.cpp
More file actions
41 lines (37 loc) · 867 Bytes
/
Copy pathC_Count_Good_Numbers.cpp
File metadata and controls
41 lines (37 loc) · 867 Bytes
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
#include <iostream>
using namespace std;
// Check if a number is prime
bool isPrime(long long n) {
if (n < 2) return false;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
// Check if a number is "good"
bool isGood(long long n) {
for (long long i = 2; i * i <= n; i++) {
while (n % i == 0) {
if (i < 10) return false; // if it has small prime factor
n /= i;
}
}
if (n > 1 && n < 10) return false; // last remaining prime < 10
return true;
}
int main() {
int t;
cin >> t;
while (t--) {
long long l, r;
cin >> l >> r;
int count = 0;
for (long long i = l; i <= r; i++) {
if (isGood(i)) {
count++;
}
}
cout << count << endl;
}
return 0;
}