Skip to content

Commit 8fa280d

Browse files
authored
Merge pull request #308 from Aaryan-Degama/main
Completed the day 1 problem 1
2 parents 26d7560 + cbf806f commit 8fa280d

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// link : https://codeforces.com/problemset/submission/1560/355483452
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
void solve(){
7+
int x, y, pos;
8+
cin >> x >> y >> pos;
9+
10+
int cs = 2 * abs(x - y);
11+
12+
int opp = pos + cs / 2;
13+
14+
if (pos > cs || y > cs || x > cs) {
15+
cout << -1 << endl;
16+
return;
17+
}
18+
19+
if (opp > cs)
20+
opp -= cs;
21+
22+
cout << opp << endl;
23+
}
24+
25+
int main(){
26+
int t;
27+
cin >> t;
28+
while (t--) solve();
29+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// link : https://codeforces.com/problemset/submission/1225/355484586
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
void solve() {
7+
int n, k;
8+
if (!(cin >> n >> k)) return;
9+
10+
vector<int> a(n);
11+
for (int &x : a) cin >> x;
12+
13+
map<vector<pair<int, int>>, long long> mp;
14+
long long res = 0;
15+
16+
for (int x : a) {
17+
int t = x;
18+
vector<pair<int, int>> current_factors, required_factors;
19+
20+
for (int p = 2; p * p <= t; p++) {
21+
if (t % p == 0) {
22+
int count = 0;
23+
while (t % p == 0) {
24+
t /= p;
25+
count++;
26+
}
27+
count %= k;
28+
if (count > 0) {
29+
current_factors.push_back({p, count});
30+
required_factors.push_back({p, k - count});
31+
}
32+
}
33+
}
34+
35+
if (t > 1) {
36+
int count = 1 % k;
37+
if (count > 0) {
38+
current_factors.push_back({t, count});
39+
required_factors.push_back({t, k - count});
40+
}
41+
}
42+
43+
if (mp.count(required_factors)) {
44+
res += mp[required_factors];
45+
}
46+
47+
mp[current_factors]++;
48+
}
49+
50+
cout << res << endl;
51+
}
52+
53+
int main() {
54+
ios::sync_with_stdio(false);
55+
cin.tie(nullptr);
56+
57+
solve();
58+
59+
return 0;
60+
}

0 commit comments

Comments
 (0)