結果
問題 | No.2066 Simple Math ! |
ユーザー |
![]() |
提出日時 | 2022-09-04 15:17:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 265 ms / 2,000 ms |
コード長 | 1,654 bytes |
コンパイル時間 | 706 ms |
コンパイル使用メモリ | 77,540 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 20:35:01 |
合計ジャッジ時間 | 7,463 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 31 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <map>#include <queue>#include <set>using namespace std;typedef long long ll;#define rep(i, n) for(int i = 0; i < (n); i++)#define dump(x) cout << #x << " = " << (x) << endl;template<class T>using vi = vector<T>;template<class T>using vii = vector<vi<T>>;template<class T>using viii = vector<vii<T>>;template<class T>T floor_sum(T n, T m, T a, T b) { //sigma(i=0~n-1){[(ai+b)/m]}T res = 0;res += (a / m) * n * (n - 1) / 2;res += (b / m) * n;a = a % m;b = b % m;T ymax = a * n + b;if (ymax < m) return res;res += floor_sum(ymax / m, a, m, ymax % m);return res;}ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }int main(){int t;cin >> t;//ACL/*while (t--) {int n, m, a, b;cin >> n >> m >> a >> b;ll ans = floor_sum<ll>(n, m, a, b);cout << ans << endl;}*///yukicoder 2066while (t--) {ll p, q, k;cin >> p >> q >> k;ll g = gcd(p, q);p /= g;q /= g;ll ok = 0, ng = min(p, q) * k + 1;while (ng - ok > 1) {ll mid = (ok + ng) / 2;ll cnt = min(mid / q, p - 1);ll n = mid / q + 1;ll m = p;ll a = q;ll b = mid % q;cnt += floor_sum<ll>(n, m, a, b);if (n >= p) cnt -= floor_sum<ll>(n - p, m, a, b);if (cnt < k) ok = mid;else ng = mid;}cout << ng * g << endl;}return 0;}// https://atcoder.jp/contests/practice2/tasks/practice2_c