Skip to content

Commit 78bb19f

Browse files
Merge branch 'main' into main
2 parents 95dd548 + acbe21b commit 78bb19f

16 files changed

Lines changed: 574 additions & 0 deletions

File tree

.DS_Store

2 KB
Binary file not shown.

Problems/.DS_Store

6 KB
Binary file not shown.

Problems/Mathematics/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.
10 KB
Binary file not shown.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* 1 to n people are standing in a circle. n is even.... a is looking at b.
2+
If given c is looking at some d person for given a,b then find that d. If such a combination
3+
of circle does not exist then print -1*/
4+
5+
// Time complexity: O(1)
6+
// Space complexity: O(1)
7+
//My submission: https://codeforces.com/contest/1560/submission/355204246
8+
9+
#include <bits/stdc++.h>
10+
using namespace std;
11+
12+
using ll = long long;
13+
#define all(x) (x).begin(), (x).end()
14+
15+
const int MOD = 1e9 + 7; // 998244353
16+
const ll INF = 1e18;
17+
18+
void solve() {
19+
int a,b,c;
20+
cin>>a>>b>>c;
21+
int n=2*abs(a-b);
22+
if(a>n || b>n ||c>n ) cout<<-1<<endl;
23+
else{
24+
int x=c-n/2,y=c+n/2;
25+
if(x>=1 && x<=n) cout<<x<<endl;
26+
else cout<<y<<endl;
27+
}
28+
}
29+
30+
int main() {
31+
// Fast I/O
32+
ios::sync_with_stdio(false);
33+
cin.tie(nullptr);
34+
35+
int t;
36+
cin >> t;
37+
while (t--) {
38+
solve();
39+
}
40+
41+
return 0;
42+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//adding submission link as suggested earlier
2+
//https://codeforces.com/problemset/submission/1560/355167404
3+
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
int main() {
8+
int t;
9+
cin >> t;
10+
while(t--) {
11+
int a,b,c;
12+
cin>>a>>b>>c;
13+
if((abs(b-a))*2<max(a,max(b,c))){
14+
cout << -1 <<'\n';
15+
continue;
16+
}
17+
if(c+(abs(b-a))>(abs(b-a)*2)){
18+
cout<<(c+(abs(b-a)))%(abs(b-a)*2)<<'\n';
19+
}
20+
else{
21+
cout<<c+(abs(b-a))<<'\n';
22+
}
23+
}
24+
25+
return 0;
26+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main() {
5+
int n, k;
6+
cin >> n >> k;
7+
8+
vector<int> a(n);
9+
for (int i = 0; i < n; i++)
10+
cin >> a[i];
11+
12+
map<vector<pair<int,int>>, long long> freq;
13+
long long ans = 0;
14+
15+
for (int i = 0; i < n; i++) {
16+
int x = a[i];
17+
vector<pair<int,int>> cur, need;
18+
19+
for (int p = 2; p * p <= x; p++) {
20+
if (x % p == 0) {
21+
int cnt = 0;
22+
while (x % p == 0) {
23+
x /= p;
24+
cnt++;
25+
}
26+
cnt %= k;
27+
if (cnt > 0) {
28+
cur.push_back({p, cnt});
29+
need.push_back({p, (k - cnt) % k});
30+
}
31+
}
32+
}
33+
34+
if (x > 1) {
35+
cur.push_back({x, 1});
36+
need.push_back({x, (k - 1) % k});
37+
}
38+
sort(cur.begin(), cur.end());
39+
sort(need.begin(), need.end());
40+
41+
ans += freq[need];
42+
freq[cur]++;
43+
}
44+
cout << ans << "\n";
45+
return 0;
46+
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
//https://codeforces.com/contest/1560/submission/355167905
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
#define int long long
6+
#define ll long long
7+
#define ull unsigned long long
8+
#define ld long double
9+
#define pii pair<int,int>
10+
#define vi vector<int>
11+
#define vvi vector<vector<int>>
12+
#define vpi vector<pair<int,int>>
13+
#define all(x) (x).begin(), (x).end()
14+
15+
16+
const long long MAXN = 2e6;
17+
const long long MOD = 1e9 + 7;
18+
const int INF = 1e18;
19+
const ld EPS = 1e-9;
20+
21+
22+
#define fastio ios::sync_with_stdio(false); cin.tie(nullptr);
23+
24+
#ifndef ONLINE_JUDGE
25+
#define debug(x) cerr << #x << " = " << x << "\n";
26+
#else
27+
#define debug(x)
28+
#endif
29+
30+
// Utility functions
31+
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
32+
int lcm(int a, int b) { return a / gcd(a, b) * b; }
33+
int mod_add(int a, int b, int m=MOD) { return ((a % m) + (b % m) + m) % m; }
34+
int mod_sub(int a, int b, int m=MOD) { return ((a % m) - (b % m) + m) % m; }
35+
int mod_mul(int a, int b, int m=MOD) { return ((a % m) * (b % m)) % m; }
36+
37+
//Binary Exponentiation
38+
int binexp(int a, int b, int m=MOD) {
39+
int res = 1;
40+
a %= m;
41+
while(b > 0) {
42+
if(b & 1) res = (res * a) % m;
43+
a = (a * a) % m;
44+
b >>= 1;
45+
}
46+
return res;
47+
}
48+
49+
int mod_inv(int a, int m=MOD) {
50+
return binexp(a, m - 2, m);
51+
}
52+
53+
long long fac[MAXN + 1];
54+
long long inv[MAXN + 1];
55+
56+
long long exp(long long x, long long n, long long m) {
57+
x %= m;
58+
long long res = 1;
59+
while (n > 0) {
60+
if (n % 2 == 1) { res = res * x % m; }
61+
x = x * x % m;
62+
n /= 2;
63+
}
64+
return res;
65+
}
66+
67+
void factorial() {
68+
fac[0] = 1;
69+
for (long long i = 1; i <= MAXN; i++) { fac[i] = fac[i - 1] * i % MOD; }
70+
}
71+
72+
void inverses() {
73+
inv[MAXN] = exp(fac[MAXN], MOD - 2, MOD);
74+
for (long long i = MAXN; i >= 1; i--) { inv[i - 1] = inv[i] * i % MOD; }
75+
}
76+
77+
long long choose(long long n, long long r) {
78+
if (r > n)return 0ll;
79+
return (fac[n] * inv[r] % MOD * inv[n - r] % MOD) % MOD;
80+
}
81+
82+
long long catalan(long long n) {
83+
return (exp(n + 1, MOD - 2, MOD) % MOD * choose(2 * n, n) % MOD) % MOD;
84+
}
85+
86+
//Returns all prime numbers <=N
87+
vector<int> sieve(int n) {
88+
vector<bool> prime(n + 1, true);
89+
for (int p=2;p*p<=n;p++) {
90+
if (prime[p] == true) {
91+
92+
for (int i=p*p;i<=n;i+=p)
93+
prime[i] = false;
94+
}
95+
}
96+
97+
vector<int> res;
98+
for (int p = 2; p <= n; p++){
99+
if (prime[p]){
100+
res.push_back(p);
101+
}
102+
}
103+
return res;
104+
}
105+
106+
//Prime factors of all numbers upto N
107+
vector<vector<int>> primefactors(int N)
108+
{
109+
vvi pfac(N + 1);
110+
for (int i=2;i<=N;i++){
111+
if (!pfac[i].empty())
112+
continue;
113+
114+
for (int j = i; j <= N; j += i)
115+
pfac[j].push_back(i);
116+
}
117+
118+
return pfac;
119+
}
120+
121+
//smallest prime factor of a number
122+
int spf(int n) {
123+
if (n % 2 == 0) return 2;
124+
for (int i = 3; i * i <= n; i += 2) {
125+
if (n % i == 0) return i;
126+
}
127+
return n;
128+
}
129+
130+
int power2(int p)
131+
{
132+
int v=1ll<<p;
133+
return v;
134+
}
135+
136+
//Sort functions
137+
138+
void sort(vector<int>&a)
139+
{
140+
sort(a.begin(),a.end());
141+
}
142+
143+
void psort(vector<pair<int,int>>&a)
144+
{
145+
sort(a.begin(),a.end());
146+
}
147+
148+
void rsort(vector<int>&a)
149+
{
150+
sort(a.rbegin(),a.rend());
151+
}
152+
153+
void rpsort(vector<pair<int,int>>&a)
154+
{
155+
sort(a.rbegin(),a.rend());
156+
}
157+
158+
//2-D Vector Declaration:
159+
//vvi mat(n,vi(m)); // nxm matrix, all initialized to 0
160+
161+
162+
/***************Code***************/
163+
164+
void solve() {
165+
166+
int a,b,c;
167+
cin>>a>>b>>c;
168+
169+
int diff=abs(a-b);
170+
int p=2*diff;
171+
if(a<=p&&b<=p&&c<=p)
172+
{
173+
if(c>diff)
174+
cout<<c-diff<<endl;
175+
else
176+
cout<<c+diff<<endl;
177+
}
178+
else
179+
cout<<"-1"<<endl;
180+
}
181+
182+
183+
signed main() {
184+
fastio;
185+
int t = 1;
186+
cin >> t;
187+
while (t--) {
188+
solve();
189+
}
190+
return 0;
191+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ti=int(input())
2+
3+
for _ in range(ti):
4+
k,l,p=map(int,input().split())
5+
6+
d=abs(k-l)
7+
f=2*d
8+
9+
if k>f or l>f or p>f:
10+
print(-1)
11+
else:
12+
if p+d<=f:
13+
print(p+d)
14+
else:
15+
print(p-d)

0 commit comments

Comments
 (0)