Skip to content

Commit 5495a67

Browse files
Merge branch 'opencodeiiita:main' into Arnav
2 parents b91e527 + 66e1c4d commit 5495a67

35 files changed

Lines changed: 1742 additions & 1 deletion

File tree

.DS_Store

0 Bytes
Binary file not shown.

Problems/.DS_Store

0 Bytes
Binary file not shown.

Problems/Mathematics/.DS_Store

2 KB
Binary file not shown.
0 Bytes
Binary file not shown.
8 KB
Binary file not shown.
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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// link : https://codeforces.com/problemset/submission/1225/355484586
2+
3+
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
void solve() {
8+
int n, k;
9+
if (!(cin >> n >> k)) return;
10+
11+
vector<int> a(n);
12+
for (int &x : a) cin >> x;
13+
14+
map<vector<pair<int, int>>, long long> mp;
15+
long long res = 0;
16+
17+
for (int x : a) {
18+
int t = x;
19+
vector<pair<int, int>> current_factors, required_factors;
20+
21+
for (int p = 2; p * p <= t; p++) {
22+
if (t % p == 0) {
23+
int count = 0;
24+
while (t % p == 0) {
25+
t /= p;
26+
count++;
27+
}
28+
count %= k;
29+
if (count > 0) {
30+
current_factors.push_back({p, count});
31+
required_factors.push_back({p, k - count});
32+
}
33+
}
34+
}
35+
36+
if (t > 1) {
37+
int count = 1 % k;
38+
if (count > 0) {
39+
current_factors.push_back({t, count});
40+
required_factors.push_back({t, k - count});
41+
}
42+
}
43+
44+
if (mp.count(required_factors)) {
45+
res += mp[required_factors];
46+
}
47+
48+
mp[current_factors]++;
49+
}
50+
51+
cout << res << endl;
52+
}
53+
54+
int main() {
55+
ios::sync_with_stdio(false);
56+
cin.tie(nullptr);
57+
58+
solve();
59+
60+
return 0;
61+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
DAY 1
3+
Q1 Who's Opposite?
4+
.*/
5+
6+
typedef long long ll;
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
10+
int main() {
11+
int t;
12+
cin>>t;
13+
while(t--){
14+
ll a, b, c;
15+
cin >> a >> b >> c;
16+
17+
ll diff = abs(a - b);
18+
ll n = 2 * diff;
19+
20+
if (diff==0 || max({a,b,c})> n){
21+
cout << -1 << endl;
22+
} else {
23+
ll d = c + diff;
24+
if (d > n) d -= n;
25+
cout << d << endl;
26+
}
27+
}
28+
return 0;
29+
}
30+
/*
31+
My submission : https://codeforces.com/contest/1560/submission/355307599
32+
*/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
DAY 1
3+
Q2 Power Products
4+
.*/
5+
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
9+
// Function to factorize a number and return prime exponents modulo k
10+
map<int, int> factorizeMod(long long x, int k) {
11+
map<int, int> factors;
12+
for (long long p = 2; p * p <= x; ++p) {
13+
int count = 0;
14+
while (x % p == 0) {
15+
x /= p;
16+
count++;
17+
}
18+
if (count % k != 0) {
19+
factors[p] = count % k; // only store modulo k
20+
}
21+
}
22+
if (x > 1) factors[x] = 1 % k; // remaining prime factor
23+
return factors;
24+
}
25+
26+
// Function to compute the complement signature modulo k
27+
map<int, int> complementSignature(const map<int, int>& sig, int k) {
28+
map<int, int> comp;
29+
for (auto &[prime, exp] : sig) {
30+
comp[prime] = (k - exp) % k;
31+
}
32+
return comp;
33+
}
34+
35+
int main() {
36+
37+
int n, k;
38+
cin >> n >> k;
39+
vector<long long> a(n);
40+
for (int i = 0; i < n; ++i) cin >> a[i];
41+
42+
// Map to count how many times each signature has occurred
43+
map<map<int,int>, long long> signatureCount;
44+
long long totalPairs = 0;
45+
46+
for (int i = 0; i < n; ++i) {
47+
map<int,int> sig = factorizeMod(a[i], k);
48+
map<int,int> comp = complementSignature(sig, k);
49+
50+
// Add pairs that match the complement
51+
totalPairs += signatureCount[comp];
52+
53+
// Increment count of current signature
54+
signatureCount[sig]++;
55+
}
56+
57+
cout << totalPairs << "\n";
58+
return 0;
59+
}
60+
61+
62+
/*
63+
My submission : https://codeforces.com/contest/1225/submission/355325134
64+
*/
1.57 KB
Binary file not shown.

0 commit comments

Comments
 (0)