Skip to content

Commit ca32973

Browse files
authored
Merge branch 'main' into main
2 parents 783e7c4 + 90a1de7 commit ca32973

24 files changed

Lines changed: 1858 additions & 15 deletions

File tree

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: 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: 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+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 vi vector<int>
9+
#define vl vector<ll>
10+
#define pii pair<int,int>
11+
#define pll pair<ll,ll>
12+
#define vpii vector<pii>
13+
#define vpll vector<pll>
14+
#define all(x) (x).begin(), (x).end()
15+
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
16+
17+
const ll MOD = 1e9+7;
18+
const ll INF = 1e18;
19+
/*
20+
We need to count the no of pairs such that their product makes some number's k-th power-this means the product of the two numbers should have
21+
factors frequency that is divisible by k. For every number first factorize it using spf(also store its factors mod k) and also store how much
22+
factor more it needs to make the k-th power add this for all numbers.
23+
24+
*/
25+
26+
/* Submission Link: https://codeforces.com/contest/1225/submission/355183203 */
27+
void solve() {
28+
int n,k;
29+
cin>>n>>k;
30+
vi a(n);
31+
f(i,0,n) cin>>a[i];
32+
vi spf(1e5+1);
33+
f(i,1,1e5+1) spf[i]=i;
34+
for(int i=2;i*i<=1e5;i++){
35+
if(spf[i]==i){
36+
for(int j=i*i;j<=1e5;j+=i){
37+
if(spf[j]==j){
38+
spf[j]=i;
39+
}
40+
}
41+
}
42+
}
43+
map<vpii,ll> cnt;
44+
ll ans=0;
45+
for(int x:a){
46+
map<int,int> factors;
47+
while(x>1){
48+
int p=spf[x];
49+
int c=0;
50+
while(x%p==0){
51+
x/=p;
52+
c++;
53+
}
54+
c%=k;
55+
if(c>0)
56+
factors[p]=c;
57+
}
58+
vpii key,need;
59+
for(auto &it:factors){
60+
key.pb(it);
61+
int y=(k-it.second)%k;
62+
if(y>0){
63+
need.pb({it.first,y});
64+
}
65+
}
66+
ans+=cnt[need];
67+
cnt[key]++;
68+
}
69+
cout<<ans<<endl;
70+
}
71+
72+
int main() {
73+
fast_io;
74+
int t = 1;
75+
//cin >> t;
76+
while(t--) solve();
77+
return 0;
78+
}

0 commit comments

Comments
 (0)