File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-01/sol/Aditi_Guin Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ using namespace std ;
3+
4+ int main () {
5+ int t;
6+ cin >> t;
7+
8+ while (t--) {
9+ int a, b, c;
10+ cin >> a >> b >> c;
11+
12+ int half = abs (a - b);
13+ int n = 2 * half;
14+
15+ if (c > n) {
16+ cout << -1 << " \n " ;
17+ } else {
18+ int opposite = (c + half <= n) ? (c + half) : (c - half);
19+ cout << opposite << " \n " ;
20+ }
21+ }
22+ return 0 ;
23+ }
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ using namespace std ;
3+
4+ int main () {
5+ ios::sync_with_stdio (false );
6+ cin.tie (nullptr );
7+
8+ int n, k;
9+ cin >> n >> k;
10+
11+ vector<int > a (n);
12+ for (int &x : a) cin >> x;
13+
14+ map<vector<pair<int ,int >>, long long > freq;
15+ long long ans = 0 ;
16+
17+ for (int x : a) {
18+ int temp = x;
19+ vector<pair<int ,int >> cur, need;
20+
21+ for (int p = 2 ; p * p <= temp; p++) {
22+ if (temp % p == 0 ) {
23+ int cnt = 0 ;
24+ while (temp % p == 0 ) {
25+ temp /= p;
26+ cnt++;
27+ }
28+ cnt %= k;
29+ if (cnt) {
30+ cur.push_back ({p, cnt});
31+ need.push_back ({p, (k - cnt) % k});
32+ }
33+ }
34+ }
35+
36+ if (temp > 1 ) {
37+ cur.push_back ({temp, 1 % k});
38+ need.push_back ({temp, (k - 1 ) % k});
39+ }
40+
41+ ans += freq[need];
42+ freq[cur]++;
43+ }
44+
45+ cout << ans << " \n " ;
46+ return 0 ;
47+ }
You can’t perform that action at this time.
0 commit comments