-
Notifications
You must be signed in to change notification settings - Fork 1
/
08 December 3 Divisors
41 lines (38 loc) · 969 Bytes
/
08 December 3 Divisors
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
class Solution
{
public:
vector<int> threeDivisors(vector<long long> query, int q)
{ vector<int> ret;
long long maxele=LONG_LONG_MIN;
for(int j=0;j<q;j++){
if(query[j]>maxele)
maxele=query[j];
}
bool prime[(int)sqrt(maxele)+1];
prime[0]=0;
prime[1]=0;
for(long long i=2;i<=sqrt(maxele);i++){
if(check_prime(i)){
prime[i]=true;
}else{
prime[i]=false;
}
}
for(int j=0;j<q;j++){
int count=0;
for(long long i=2;i<=sqrt(query[j]);i++){
if(prime[i])
count++;
}
ret.push_back(count);
}
return ret;
}
bool check_prime(int k){
for(int i=2;i<=sqrt(k);i++){
if(k%i==0)
return false;
}
return true;
}
};