結果

問題 No.816 Beautiful tuples
ユーザー silopy
提出日時 2019-06-22 23:11:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 690 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 75,596 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 10:18:34
合計ジャッジ時間 1,658 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#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