Skip to content

Commit 7fc8a7b

Browse files
Merge branch 'main' into main
2 parents 505226e + 98005d0 commit 7fc8a7b

5 files changed

Lines changed: 126 additions & 1 deletion

File tree

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)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
int main()
6+
{
7+
int t;
8+
cin>>t;
9+
while(t--)
10+
{
11+
int a, b, c;
12+
cin>>a>>b>>c;
13+
int half=abs(b-a);
14+
int full=2*half;
15+
// cout<<full<<endl;
16+
if(a>full || b> full || c > full)
17+
{
18+
cout<<-1<<endl;
19+
}
20+
else
21+
{
22+
int ans=c+half;
23+
if(ans>full)
24+
{
25+
ans-=full;
26+
}
27+
cout<<ans<<endl;
28+
}
29+
30+
}
31+
32+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def solve():
2+
t = int(input())
3+
for _ in range(t):
4+
a, b, c = map(int, input().split())
5+
6+
d = abs(a - b)
7+
n = 2 * d
8+
9+
10+
if n == 0 or max(a, b, c) > n:
11+
print(-1)
12+
continue
13+
14+
half = n // 2
15+
16+
if c + half <= n:
17+
print(c + half)
18+
else:
19+
print(c - half)
20+
21+
solve()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def solve():
2+
t = int(input())
3+
for _ in range(t):
4+
a, b, c = map(int, input().split())
5+
6+
d = abs(a - b)
7+
n = 2 * d
8+
9+
if n == 0 or max(a, b, c) > n:
10+
print(-1)
11+
continue
12+
13+
half = n // 2
14+
15+
if c + half <= n:
16+
print(c + half)
17+
else:
18+
print(c - half)
19+
20+
# Run
21+
solve()

contributers.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
| Name | GitHub ID | College Name |
32
|------------------------|-------------------------|------------------------------------------------------------------|
43
| Pradip Maity | @codeboy-pro | Haldia Institute Of Technology |
@@ -26,5 +25,7 @@
2625
| Ishan Tripathi | ishantripathi64 | IIIT Allahabad |
2726
| Lavay Garg | lavaygarg | IIIT Allahabad |
2827
| Himanshu Vitthalani | Himanshu-1903 | IIIT Allahabad
28+
| Abhishek Tripathi | Astinel-prime | IIIT Allahabd |
29+
| Ibrahim Raza Beg | PHOX-9 | IIIT Allahabd |
2930
<!-- ADD ABOVE THIS -->
3031
<!-- example | Korvac | Betty | Reyansh College | -->

0 commit comments

Comments
 (0)