結果

問題 No.816 Beautiful tuples
コンテスト
ユーザー silopy
提出日時 2019-06-22 23:11:48
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 1,500 ms
+ 394µs
コード長 690 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 426 ms
コンパイル使用メモリ 94,324 KB
実行使用メモリ 9,876 KB
最終ジャッジ日時 2026-10-12 19:20:51
合計ジャッジ時間 1,556 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<algorithm>
using namespace std;
using lint=int64_t;

#include<vector>
template<typename T>
void div(vector<T> &vec,T n)
{
	for(T i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			vec.push_back(i);
			if(i*i!=n)
				vec.push_back(n/i);
		}
	}
	return;
}

bool check(lint A,lint B,lint C)
{
	if(A==C)return false;
	if(B==C)return false;
	if((A+B)%C!=0)return false;
	if((B+C)%A!=0)return false;
	if((A+C)%B!=0)return false;
	return true;
}

int main()
{
	lint A,B;

	cin >> A >> B;

	vector<lint> divs;
	div(divs,A+B);

	sort(divs.begin(),divs.end());

	for(auto& i:divs)
	{
		if(check(A,B,i))
		{
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}
0