Skip to content

Commit 365f960

Browse files
authored
Merge branch 'opencodeiiita:main' into main
2 parents fe841c7 + 26d7560 commit 365f960

67 files changed

Lines changed: 3326 additions & 53 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode/

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.
12 KB
Binary file not shown.
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+
*/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
using ll = long long;
5+
const ll MOD = 998244353;
6+
7+
void solve() {
8+
int a, b, c;
9+
cin >> a >> b >> c;
10+
11+
int diff = abs(a-b);
12+
if (a > 2*diff || b > 2*diff || c > 2*diff) {
13+
cout << -1 << endl;
14+
return;
15+
}
16+
17+
int ans = c + diff;
18+
if (ans > 2*diff) {
19+
ans -= 2*diff;
20+
}
21+
22+
cout << ans << endl;
23+
24+
}
25+
26+
int main() {
27+
ios::sync_with_stdio(false);
28+
cin.tie(nullptr);
29+
30+
int t = 1;
31+
cin >> t;
32+
33+
while (t--) {
34+
solve();
35+
}
36+
37+
return 0;
38+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
static const int maxi = 100000;
5+
int spf[maxi + 1];
6+
int k;
7+
8+
/*sieve*/
9+
void buildSPF() {
10+
for (int i = 1; i <= maxi; i++)
11+
spf[i] = i;
12+
13+
for (int i = 2; i * i <= maxi; i++) {
14+
if (spf[i] == i) {
15+
for (int j = i * i; j <= maxi; j += i) {
16+
if (spf[j] == j)
17+
spf[j] = i;
18+
}
19+
}
20+
}
21+
}
22+
23+
/*factorise*/
24+
vector<pair<int,int>> getSignature(int x) {
25+
map<int,int> factors;
26+
27+
while (x > 1) {
28+
int p = spf[x];
29+
factors[p]++;
30+
x /= p;
31+
}
32+
33+
vector<pair<int,int>> sig;
34+
for (auto &it : factors) {
35+
int exp = it.second % k;
36+
if (exp != 0)
37+
sig.push_back({it.first, exp});
38+
}
39+
return sig;
40+
}
41+
42+
/*how many needed*/
43+
vector<pair<int,int>> getComplement(const vector<pair<int,int>> &sig) {
44+
vector<pair<int,int>> comp;
45+
for (auto &p : sig) {
46+
comp.push_back({p.first, (k - p.second) % k});
47+
}
48+
return comp;
49+
}
50+
51+
int main() {
52+
ios::sync_with_stdio(false);
53+
cin.tie(nullptr);
54+
55+
int n;
56+
cin >> n >> k;
57+
58+
vector<int> a(n);
59+
for (int i = 0; i < n; i++)
60+
cin >> a[i];
61+
62+
buildSPF();
63+
64+
map<vector<pair<int,int>>, long long> freq;
65+
long long ans = 0;
66+
67+
for (int i = 0; i < n; i++) {
68+
vector<pair<int,int>> sig = getSignature(a[i]);
69+
vector<pair<int,int>> need = getComplement(sig);
70+
ans += freq[need];
71+
freq[sig]++;
72+
}
73+
cout << ans << "\n";
74+
return 0;
75+
}
76+
//https://codeforces.com/problemset/submission/1225/355302622
77+
//time complexity O(nlognlog(10^5))

0 commit comments

Comments
 (0)