結果

問題 No.816 Beautiful tuples
コンテスト
ユーザー Cooh
提出日時 2019-06-02 01:31:00
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 759 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 601 ms
コンパイル使用メモリ 78,956 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-06 10:44:59
合計ジャッジ時間 6,489 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<string>
#include<vector>
using namespace std;

int Enjapma(int A, int B) {
	if (A == B) {
		return -1;
	}

	int D = A + B;
	vector<int> div;
	for (int i = 1; i < (D / 2); i++) {
		if (D%i == 0) {
			div.insert(div.begin(), i);
		}
	}
	
	vector<int> Bans;
	vector<int>::iterator a = div.begin();
	while (a != div.end()) {
		if ((A + *a) % B == 0) {
			Bans.insert(Bans.begin(), *a);
		}
		a++;
	}
	int ans = -1;
	vector<int>::iterator b = Bans.begin();
	while (b != Bans.end()) {
		if ((B + *b) % A == 0) {
			ans = *b;
		}
		b++;
	}

	if (A == ans) { ans = -1; }
	if (B == ans) { ans = -1; }
	return ans;

}
int main() {
	int A, B;
	cout << "A B > "; cin >> A >> B;

	cout << Enjapma(A, B) << endl;

	system("pause");
	return 0;

}
0