-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlices_Adventure_in_Permuting.cpp
More file actions
129 lines (117 loc) · 3.25 KB
/
Alices_Adventure_in_Permuting.cpp
File metadata and controls
129 lines (117 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// બધા માટે રામ રામ, ભગવાનનું નામ લો અને તમારું કાર્ય શરૂ કરો.
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Fast I/O setup
struct FastIO {
FastIO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
} fast_io_setup;
// Binary Search Function
int binary_search(vector<int>& arr, int target) {
int left = 0, right = arr.size() - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == target) return mid;
if (arr[mid] < target) left = mid + 1;
else right = mid - 1;
}
return -1;
}
// Custom Power Function (Efficient Modular Exponentiation)
ll power(ll base, ll exp, ll mod = 1e9+7) {
ll result = 1;
while (exp > 0) {
if (exp % 2 == 1) result = (result * base) % mod;
base = (base * base) % mod;
exp /= 2;
}
return result;
}
// Sieve of Eratosthenes for Prime Numbers
vector<int> sieve(int n) {
vector<int> is_prime(n + 1, 1);
is_prime[0] = is_prime[1] = 0;
for (int i = 2; i * i <= n; i++) {
if (is_prime[i]) {
for (int j = i * i; j <= n; j += i) is_prime[j] = 0;
}
}
vector<int> primes;
for (int i = 2; i <= n; i++) {
if (is_prime[i]) primes.push_back(i);
}
return primes;
}
// Factorization to Find Prime Divisors of a Number
vector<int> prime_factors(int n) {
vector<int> factors;
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
factors.push_back(i);
n /= i;
}
}
if (n > 1) factors.push_back(n);
return factors;
}
// Square Root Calculation (Integer)
int integer_sqrt(int n) {
int left = 0, right = n, ans = -1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (mid * mid == n) return mid;
if (mid * mid < n) {
ans = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
return ans;
}
int main() {
ll testcases;
cin >> testcases;
for(ll testcase = 0; testcase < testcases; testcase++){
ll n, b, c;
cin >> n >> b >> c;
// so i want to divide the solution into 2 parts, 1st is that i will check if it -1 case by taking mex of all elements
// 2nd is the answer, that answer will be number of numbers missing from 0 to n - 1
if(b == 0){
if(c >= n){
cout << n << "\n";
}
else if(c == n - 2 || c == n - 1){
cout << n - 1 << "\n";
}
else{
cout << -1 << "\n";
}
}
else{
if(c >= n){
cout << n << "\n";
}
else{
ll help = 1 + (n - c - 1) / b;
if(help > 0){
cout << n - help << "\n";
}
else{
cout << n << "\n";
}
}
}
}
}
/*
----- ----- ----- ----
| - | | | |
| - ----- ----- |----
| - | | |
----- ----- ----- |
*/