結果

問題 No.2767 Add to Divide
ユーザー ococonomy1ococonomy1
提出日時 2024-05-31 21:55:59
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 2,092 bytes
コンパイル時間 1,110 ms
コンパイル使用メモリ 111,908 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-20 23:17:52
合計ジャッジ時間 2,115 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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(a == b){
cout << 0 << 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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0