aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4/aisd/Pracownia 1
diff options
context:
space:
mode:
Diffstat (limited to 'Semestr 4/aisd/Pracownia 1')
-rw-r--r--Semestr 4/aisd/Pracownia 1/rozw2.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/Semestr 4/aisd/Pracownia 1/rozw2.cpp b/Semestr 4/aisd/Pracownia 1/rozw2.cpp
new file mode 100644
index 0000000..35fd37e
--- /dev/null
+++ b/Semestr 4/aisd/Pracownia 1/rozw2.cpp
@@ -0,0 +1,33 @@
+#include<bits/stdc++.h>
+using namespace std;
+typedef unsigned long long ll;
+
+vector<pair<int, ll>> v;
+
+int main() {
+ int n;
+ scanf("%d", &n);
+ for (int i = 0; i < n; i++) {
+ int d, nd, k = 0;
+ scanf("%d %d", &d, &nd);
+ while (d % 2 == 0) {
+ k++;
+ d /= 2;
+ }
+ v.push_back({d, (ll)(1LL<<k) * (ll)nd});
+ }
+ sort(v.begin(), v.end());
+ int result = 0;
+ for (int i = 0; i < n; ) {
+ int j = i;
+ int cur = v[i].first;
+ ll count = 0;
+ while (j < n && v[j].first == cur) {
+ count += v[j].second;
+ ++j;
+ }
+ result += __builtin_popcountll(count);
+ i = j;
+ }
+ cout << result << "\n";
+} \ No newline at end of file