Skip to content

Commit e96ca3e

Browse files
authored
Merge branch 'main' into main
2 parents b3f1880 + 326c4b3 commit e96ca3e

53 files changed

Lines changed: 2309 additions & 50 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.
6 KB
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*We have:
2+
3+
An even number of people n standing in a circle, numbered 1 to n clockwise.
4+
5+
Each person looks directly opposite in the circle.
6+
7+
You are given three numbers: a, b, c.
8+
9+
a is looking at b.
10+
11+
We want to know who c is looking at.
12+
13+
If no circle is possible → return -1.
14+
15+
*/
16+
17+
typedef long long ll;
18+
#include <bits/stdc++.h>
19+
using namespace std;
20+
21+
int main() {
22+
int t;
23+
cin>>t;
24+
while(t--){
25+
ll a, b, c;
26+
cin >> a >> b >> c;
27+
28+
ll diff = abs(a - b);
29+
ll n = 2 * diff;
30+
31+
if (diff==0 || max({a,b,c})> n){
32+
cout << -1 << endl;
33+
} else {
34+
ll d = c + diff;
35+
if (d > n) d -= n;
36+
cout << d << endl;
37+
}
38+
}
39+
return 0;
40+
}
41+
42+
//O(1) per test case
43+
//My SUBMISSION : https://codeforces.com/contest/1560/submission/355307599
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//#include <bits/stdc++.h>
2+
#include <iostream>
3+
#include <vector>
4+
#include <string>
5+
#include <algorithm>
6+
#include <map>
7+
#include <set>
8+
#include <unordered_map>
9+
#include <queue>
10+
#include <stack>
11+
#include <cmath>
12+
#include <climits>
13+
#define int long long
14+
#define fo(n) for (int i = 0; i < n; i++)
15+
#define fo1(ii, n) for(int i=ii; i<n; i++)
16+
#define all(x) x.begin(), x.end()
17+
#define rall(x) x.rbegin(), x.rend()
18+
#define pb push_back
19+
#define fi first
20+
#define se second
21+
#define vec(a) vector<int> a
22+
#define vecn(a,n) vector<int> a(n)
23+
#define py cout<<"YES"<<endl
24+
#define pn cout<<"NO"<<endl
25+
const int MOD = 1e9 + 7;
26+
const int INF = 1e18;
27+
using namespace std;
28+
29+
void solve(){
30+
int a,b,c;
31+
cin>>a>>b>>c;
32+
//a->b
33+
//c->?
34+
int total=abs(a-b)*2;
35+
int half=total/2;
36+
if(max({a,b,c})>total){
37+
cout<<-1<<endl;
38+
return;
39+
}
40+
else if(c<=total){
41+
if(c>half){
42+
cout<<c-half<<endl;
43+
}
44+
else cout<<c+half<<endl;
45+
}
46+
}
47+
48+
signed main() {
49+
ios_base::sync_with_stdio(false);
50+
cin.tie(0);
51+
int t;
52+
cin >> t;
53+
while(t--)
54+
solve();
55+
return 0;
56+
}
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)