結果
問題 |
No.2420 Simple Problem
|
ユーザー |
![]() |
提出日時 | 2023-08-21 15:39:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 167 ms / 2,000 ms |
コード長 | 894 bytes |
コンパイル時間 | 381 ms |
コンパイル使用メモリ | 40,960 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-15 04:35:24 |
合計ジャッジ時間 | 11,539 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 33 |
ソースコード
/* -*- coding: utf-8 -*- * * 2420.cc: No.2420 Simple Problem - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int a, b; scanf("%d%d", &a, &b); // sqrt(a)+sqrt(b)<x -> (sqrt(a)+sqrt(b))^2=a+b+2sqrt(a)sqrt(b)<x^2 // -> 2sqrt(a)sqrt(b)<x^2-(a+b) -> 4ab<(x^2-(a+b))^2 ll d = 4LL * a * b; ll e0 = 0, e1 = 2000000001; while (e0 + 1 < e1) { ll e = (e0 + e1) / 2; if (e * e > d) e1 = e; else e0 = e; } //printf("e1=%lld\n", e1); ll f = e1 + (a + b); ll x0 = 0, x1 = 4000000001LL; while (x0 + 1 < x1) { ll x = (x0 + x1) / 2; if (x * x >= f) x1 = x; else x0 = x; } printf("%lld\n", x1); } return 0; }