Skip to content

Commit 00502aa

Browse files
authored
Merge branch 'main' into main
2 parents f39dabe + ca40ec2 commit 00502aa

20 files changed

Lines changed: 1329 additions & 0 deletions

File tree

.DS_Store

6 KB
Binary file not shown.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# PROBLEM STATEMENT :
2+
3+
There are **n people** standing in a circle. They are numbered from **1 to n** in a clockwise order. The circle is **even** (i.e. *n* is even).
4+
5+
Each person is looking at the person standing exactly opposite him in the circle.
6+
7+
You are given three **distinct** integers **a**, **b**, and **c**. It is known that person **a** is looking at person **b**.
8+
9+
Determine the number of the person that person **c** is looking at.
10+
If there are **multiple answers**, print **any** of them.
11+
If there is **no answer**, print **-1**.
12+
13+
---
14+
15+
## Input
16+
17+
The first line contains a single integer **t**
18+
(**1 ≤ t ≤ 10⁴**) — the number of test cases.
19+
20+
Each of the following **t** lines contains three distinct integers **a**, **b**, and **c**
21+
(**1 ≤ a, b, c ≤ 10⁸**).
22+
23+
---
24+
25+
## Output
26+
27+
For each test case, print the answer —
28+
the number of the person that person **c** is looking at,
29+
or **-1** if the answer does not exist.
30+
31+
---
32+
33+
## Example
34+
35+
### Input
36+
```
37+
7
38+
6 2 4
39+
2 3 1
40+
2 4 10
41+
5 3 4
42+
1 3 2
43+
2 5 4
44+
4 3 2
45+
```
46+
47+
48+
### Output
49+
```
50+
8
51+
-1
52+
-1
53+
-1
54+
4
55+
1
56+
-1
57+
```
58+
The problem statement is given just in case the codeforces server lags.<br>
59+
Submit your solution in the link given below and send a PR upon receiving AC.
60+
61+
[PROBLEM LINK](https://codeforces.com/problemset/problem/1560/B)
62+
63+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Problem Description
2+
3+
You are given an integer `n` and an integer `k` (`k ≥ 2`), along with an array of `n` positive integers
4+
`a1, a2, ..., an`.
5+
6+
Your task is to count the number of unordered index pairs `(i, j)` such that:
7+
8+
- `1 ≤ i < j ≤ n`
9+
- The product `ai × aj` is a **perfect k-th power**
10+
11+
A number is called a perfect k-th power if it can be written in the form `x^k` for some integer `x`.
12+
13+
---
14+
15+
## Input Format
16+
17+
- The first line contains two integers `n` and `k`.
18+
- The second line contains `n` integers `a1, a2, ..., an`.
19+
20+
---
21+
22+
## Output Format
23+
24+
- Print a single integer — the number of valid pairs `(i, j)`.
25+
26+
---
27+
28+
## Constraints
29+
30+
- `2 ≤ n ≤ 100000`
31+
- `2 ≤ k ≤ 100`
32+
- `1 ≤ ai ≤ 100000`
33+
34+
---
35+
36+
## Sample Input
37+
38+
```
39+
6 3
40+
1 3 9 8 24 1
41+
```
42+
---
43+
44+
## Output
45+
46+
```
47+
5
48+
```
49+
50+
[PROBLEM LINK]( https://codeforces.com/problemset/problem/1225/D)

Problems/Mathematics/Day-01/q1.cpp

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main() {
5+
int t;
6+
cin >> t;
7+
while (t--) {
8+
int a, b, c;
9+
cin >> a >> b >> c;
10+
11+
int diff = abs(a - b);
12+
int n = 2 * diff;
13+
if (diff == 0 || a > n || b > n || c > n) {
14+
cout << -1 << '\n';
15+
continue;
16+
}
17+
int half = n / 2;
18+
int d;
19+
if (c + half <= n)
20+
d = c + half;
21+
else
22+
d = c - half;
23+
cout << d << '\n';
24+
}
25+
26+
return 0;
27+
}
852 Bytes
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// CODEFORCES SUBMISSION LINK: https://codeforces.com/contest/1560/submission/355168755
2+
3+
/*
4+
PROBLEM STATEMENT :
5+
6+
There are n people standing in a circle. They are numbered from 1 to n in a clockwise order. The circle is even (i.e. n is even).
7+
8+
Each person is looking at the person standing exactly opposite him in the circle.
9+
10+
You are given three distinct integers a, b, and c. It is known that person a is looking at person b.
11+
12+
Determine the number of the person that person c is looking at.
13+
If there are multiple answers, print any of them.
14+
If there is no answer, print -1.
15+
*/
16+
17+
/*
18+
Approach:
19+
We first calculate the size of the circle. Knowing 'a' and 'b' is enough to know the size of the circle.
20+
Because we can know the number of people between 'a' and 'b' which would give us half the total number.
21+
We can easily get the person sitting opposite to any number once we know the size of the circle.
22+
*/
23+
24+
/*
25+
Time Complexity: O(1)
26+
Space Complexity: O(1)
27+
*/
28+
29+
import java.util.Scanner;
30+
31+
public class Solution1 {
32+
public static void main(String[] args) {
33+
Scanner sc = new Scanner(System.in);
34+
int t = sc.nextInt();
35+
while (t-- > 0) {
36+
int a = sc.nextInt();
37+
int b = sc.nextInt();
38+
int c = sc.nextInt();
39+
int d;
40+
41+
int n = 2 * Math.abs(a - b);
42+
if (a > n || b > n || c > n)
43+
d = -1;
44+
else {
45+
int res = (c + (n / 2)) % n;
46+
d = res != 0? res : n;
47+
}
48+
49+
System.out.println(d);
50+
}
51+
sc.close();
52+
}
53+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
//Time: O(t)
3+
4+
//Space: O(1)
5+
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
int main(){
9+
int t;
10+
cin >> t;
11+
while(t--){
12+
long long a, b, c;
13+
cin >> a >> b >> c;
14+
long long dist=llabs(a - b);
15+
long long n=2*dist;
16+
if(dist==0 || c>n){
17+
cout << -1 << '\n';
18+
continue;
19+
}
20+
long long half=n/2;
21+
if(c+half<=n){
22+
cout << c+half << '\n';
23+
}
24+
else{
25+
cout << c-half << '\n';
26+
27+
}
28+
}
29+
return 0;
30+
}
31+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define ll long long
5+
#define pb push_back
6+
#define f(i,a,b) for (ll i = a; i < b; i++)
7+
#define fb(i,a,b) for (ll i = a; i >= b; i--)
8+
#define all(v) (v).begin(), (v).end()
9+
10+
typedef vector<int> vi;
11+
typedef vector<ll> vl;
12+
typedef pair<int,int> pii;
13+
typedef pair<ll,ll> pll;
14+
15+
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
16+
17+
ll binexp(ll a, ll b) {
18+
ll res = 1;
19+
while (b > 0) {
20+
if (b & 1) res = res * a;
21+
a = a * a;
22+
b >>= 1;
23+
}
24+
return res;
25+
}
26+
27+
void solve() {
28+
int a,b,c;
29+
cin>>a>>b>>c;
30+
if(c>2*abs(a-b) or a>2*abs(a-b) or b>2*(abs(a-b))){
31+
cout<<-1<<endl;
32+
}
33+
else{
34+
if(c>abs(a-b)) cout<<c-abs(a-b)<<endl;
35+
else cout<<c+abs(a-b)<<endl;
36+
}
37+
}
38+
39+
int main() {
40+
fastio;
41+
int t = 1;
42+
cin >> t;
43+
while (t--) solve();
44+
}

0 commit comments

Comments
 (0)