QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#823379 | #9864. Coin | LeoG | TL | 17ms | 3656kb | C++23 | 3.3kb | 2024-12-20 22:48:08 | 2024-12-20 22:48:08 |
Judging History
answer
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#define ll long long
#define all(v) v.begin(),v.end()
#define ld long double
#define pll std::pair<ll,ll>
#define pi std::pair<int,int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define len(x) (int)x.size()
#define vec(T) std::vector<T>
#define PI (ld)3.14159265358979323846
// overload << for pair
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::pair<T, T>& pair) {
std::cout << "(" << pair.first << ", " << pair.second << ")";
return os;
}
// overload << for vec
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
os << "[";
for (size_t i = 0; i < vec.size(); ++i) {
os << vec[i] << (i == vec.size() - 1 ? "\0" : ", ");
}
os << "]";
return os;
}
// overload << for map and unordered_map Output
template<typename Map>
void printMap(const Map& m) {
std::cout << '{';
for (auto it = m.begin(); it != m.end(); it++) {
std::cout << it -> first << ": " << it -> second << (std::next(it) == m.end() ? "\0" : ", ");
}
std::cout << "}";
}
template <typename K, typename V>
std::ostream& operator<<(std::ostream& os, const std::map<K, V>& m) {
printMap(m);
return os;
}
template <typename K, typename V>
std::ostream& operator<<(std::ostream& os, const std::unordered_map<K, V>& m) {
printMap(m);
return os;
}
// overload << for set and unordered_set Output
template<typename Set>
void printSet(const Set& s) {
std::cout << '{';
for (auto it = s.begin(); it != s.end(); it++) {
std::cout << *it << (std::next(it) == s.end() ? "\0" : ", ");
}
std::cout << "}";
}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
printSet(s);
return os;
}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::unordered_set<T>& s) {
printSet(s);
return os;
}
// General print function
template <typename T>
void print(const T& val) {
std::cout << val << std::endl;
}
// Variadic template print function
template<typename T, typename... Args>
void print(const T& t, const Args&... args) {
std::cout << t << ' ';
print(args...);
if (sizeof...(args) == 1) std::cout << '\n';
}
void solve(){
ll n, m;
std::cin >> n >> m;
ll x = m - 1;
auto f = [&](ll t) {
ll l = t, r = n;
while (l < r) {
ll mid = (l + r) / 2;
if (mid - mid / m - 1 >= x) {
r = mid;
}
else {
l = mid + 1;
}
}
return l;
};
if (n <= m) {
print(n);
return;
}
while (true) {
ll tmp = f(x);
if (tmp >= n) break;
x = tmp;
}
print(x + 1);
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 17ms
memory: 3592kb
input:
4 6 2 8 3 10000 2 1919810 114514
output:
4 8 8192 1919805
result:
ok 4 number(s): "4 8 8192 1919805"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
100 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 10 5 11 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 6 10 6 11 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 7 10 7 11 8 2 8 3 8 4 8 5 8 6 8 7 8 8 8 9 8 10 8 11 9 ...
output:
2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 4 3 4 4 4 4 4 4 4 4 4 5 4 5 5 5 5 5 5 5 4 5 6 5 6 6 6 6 6 6 4 5 6 7 6 7 7 7 7 7 8 8 8 7 8 7 8 8 8 8 8 8 8 9 8 9 8 9 9 9 8 8 8 9 10 9 10 9 10 10 8 8 11 9 10 11 10 11 10 11
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
100 100 10 100 11 100 12 100 13 100 14 100 15 100 16 100 17 100 18 100 19 101 10 101 11 101 12 101 13 101 14 101 15 101 16 101 17 101 18 101 19 102 10 102 11 102 12 102 13 102 14 102 15 102 16 102 17 102 18 102 19 103 10 103 11 103 12 103 13 103 14 103 15 103 16 103 17 103 18 103 19 104 10 104 11 10...
output:
93 94 92 98 98 94 96 100 96 95 93 94 101 98 98 101 96 100 96 101 93 94 101 98 98 101 96 100 102 101 93 94 101 98 98 101 103 100 102 101 104 104 101 98 98 101 103 100 102 101 104 104 101 98 98 101 103 100 102 101 104 104 101 98 106 101 103 100 102 101 104 104 101 107 106 101 103 107 102 107 104 104 1...
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
100 10000 2 10000 3 10000 4 10000 5 10000 6 10000 7 10000 8 10000 9 10000 10 10000 11 10001 2 10001 3 10001 4 10001 5 10001 6 10001 7 10001 8 10001 9 10001 10 10001 11 10002 2 10002 3 10002 4 10002 5 10002 6 10002 7 10002 8 10002 9 10002 10 10002 11 10003 2 10003 3 10003 4 10003 5 10003 6 10003 7 10...
output:
8192 8091 8719 8279 9885 8980 8933 9756 9938 9526 8192 8091 8719 8279 9885 8980 8933 9756 9938 9526 8192 8091 8719 8279 9885 8980 8933 9756 9938 9526 8192 8091 8719 8279 9885 8980 8933 9756 9938 9526 8192 8091 8719 8279 9885 8980 8933 9756 9938 9526 8192 8091 8719 8279 9885 8980 8933 9756 9938 9526 ...
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
100 10000 10 10000 11 10000 12 10000 13 10000 14 10000 15 10000 16 10000 17 10000 18 10000 19 10001 10 10001 11 10001 12 10001 13 10001 14 10001 15 10001 16 10001 17 10001 18 10001 19 10002 10 10002 11 10002 12 10002 13 10002 14 10002 15 10002 16 10002 17 10002 18 10002 19 10003 10 10003 11 10003 12...
output:
9938 9526 9903 9913 9713 9441 9949 9599 9984 9683 9938 9526 9903 9913 9713 9441 9949 9599 9984 9683 9938 9526 9903 9913 9713 9441 9949 9599 9984 9683 9938 9526 9903 9913 9713 9441 9949 9599 9984 9683 9938 9526 9903 9913 9713 9441 9949 9599 9984 9683 9938 9526 9903 9913 9713 9441 9949 9599 9984 9683 ...
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 5ms
memory: 3656kb
input:
100 100000 100 100000 101 100000 102 100000 103 100000 104 100000 105 100000 106 100000 107 100000 108 100000 109 100001 100 100001 101 100001 102 100001 103 100001 104 100001 105 100001 106 100001 107 100001 108 100001 109 100002 100 100002 101 100002 102 100002 103 100002 104 100002 105 100002 106...
output:
99125 99684 99115 99174 99331 99117 99518 99951 99671 99544 99125 99684 99115 99174 99331 99117 99518 99951 99671 99544 99125 99684 99115 99174 99331 99117 99518 99951 99671 99544 99125 99684 99115 99174 99331 99117 99518 99951 99671 99544 99125 99684 99115 99174 99331 99117 99518 99951 99671 99544 ...
result:
ok 100 numbers
Test #7:
score: -100
Time Limit Exceeded
input:
100 9829300000 1000000000 9829300000 1000000001 9829300000 1000000002 9829300000 1000000003 9829300000 1000000004 9829300000 1000000005 9829300000 1000000006 9829300000 1000000007 9829300000 1000000008 9829300000 1000000009 9829300001 1000000000 9829300001 1000000001 9829300001 1000000002 9829300001...