結果

問題 No.2767 Add to Divide
ユーザー ococonomy1ococonomy1
提出日時 2024-05-31 21:51:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,096 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 111,480 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-31 21:52:05
合計ジャッジ時間 2,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 31 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 15 ms
6,944 KB
testcase_06 WA -
testcase_07 AC 15 ms
6,940 KB
testcase_08 AC 26 ms
6,944 KB
testcase_09 WA -
testcase_10 AC 26 ms
6,940 KB
testcase_11 AC 26 ms
6,940 KB
testcase_12 AC 25 ms
6,944 KB
testcase_13 AC 25 ms
6,944 KB
testcase_14 AC 25 ms
6,944 KB
testcase_15 AC 24 ms
6,940 KB
testcase_16 AC 26 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
//#define AMARI 1000000007
#define el '\n'
#define El '\n'

#define MULTI_TEST_CASE true 
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //一個回答に繋がりそうな解法が見えても、実装や細かい詰めに時間がかかりそうなら別の方針を考えてみる
    //添え字回りで面倒になりそうなときは楽になる言い換えを実装の前にじっくり考える
    //ある程度考察しても全然取っ掛かりが見えないときは実験をしてみる
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
    ll a,b;
    cin >> a >> b;
    if(b < 2 * a){
        cout << -1 << el;
        return;
    }
    ll dif = b - a;
    vector<ll> yakusuu;
    for(int i = 1; i * i <= dif; i++){
        if(dif % i == 0){
            yakusuu.push_back(i);
            if(i * i != dif)yakusuu.push_back(dif / i);
        }
    }
    ll ans = LLONG_MAX;
    for(int i = 0; i < yakusuu.size(); i++){
        ll k = yakusuu[i];
        //a + x == k
        ll x = k - a;
        if(x < 0)continue;
        if((b + x) % (a + x) == 0)ans = min(ans,x);
    }
    if(ans == LLONG_MAX)cout << -1 << el;
    else cout << ans << el;
    return;
}

void calc(void){
    return;
}

signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0