-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cpp
More file actions
36 lines (33 loc) · 717 Bytes
/
Solution.cpp
File metadata and controls
36 lines (33 loc) · 717 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
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int sumFourDivisors(vector<int> &nums) {
int totalSum = 0;
for (int n : nums) {
vector<int> divisori;
int limite = sqrt(n);
for (int j = 1; j * j <= n; ++j) {
if (n % j == 0) {
divisori.push_back(j);
if (j * j != n) {
divisori.push_back(n / j);
}
}
}
if (divisori.size() == 4) {
for (int d : divisori) {
totalSum += d;
}
}
}
return totalSum;
}
};
int main() {
vector<int> nums{21, 4, 7};
int risultato = Solution().sumFourDivisors(nums);
cout << risultato << endl;
}