-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path108.cpp
More file actions
44 lines (41 loc) · 919 Bytes
/
Copy path108.cpp
File metadata and controls
44 lines (41 loc) · 919 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
42
43
44
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
bool isPerfectSquare(int num) {
double sq = sqrt(num);
return sq == (int)sq;
}
vector<int> generateNoOfDivisorsSieve(int num){
vector<int> arr = vector<int>(num+1,2);
arr[0] = 0,arr[1] = 1;
for (int i = 2; i <= (num * num)/2; i++) {
for (int j = 2; j * i <= num * num; j++) {
if(isPerfectSquare(i*j)) arr[(int)sqrt(i * j)] ++;
}
}
return arr;
}
void printVector(vector<int> vec){
for (size_t i = 0; i < vec.size(); i++) {
cout<<vec[i]<<"\t";
}
cout<<endl;
}
int main() {
int n = 40000;
vector<int> noOfDivisors = generateNoOfDivisorsSieve(n);
int max = 0;
for (size_t i = 2; i < n; i++) {
if(noOfDivisors[i] > max) {
max = noOfDivisors[i];
}
if(noOfDivisors[i] > 1000){
cout<<i<<endl;
break;
}
}
// printVector(noOfDivisors);
cout<<max<<endl;
return 0;
}