結果

問題 No.1200 お菓子配り-3
コンテスト
ユーザー anagohirame
提出日時 2020-08-29 16:16:35
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 402 ms / 4,000 ms
コード長 791 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,333 ms
コンパイル使用メモリ 209,440 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-13 01:41:51
合計ジャッジ時間 5,557 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main() {
	int s; scanf("%d", &s);
	for (int z = 0; z < s; ++z) {
		int x, y; scanf("%d%d", &x, &y);
		if (x == y) {
			int ans = x-1;
			for (int i = 1; i*i <= x; ++i)
			{
				if (x%i != 0) continue;
				if (i > 2) ans++;
				if (i*i < x and x/i > 2) ans++;
			}
			printf("%d\n", ans);
			continue;
		}
		if (x < y) swap(x, y);
		int ans = 0;
		for (int i = 1; i*i <= x-y; ++i) {
			if ((x-y) % i != 0) continue;
			if ((x+y) % (i+2) == 0) {
				int p = (x-y) / i; int q = (x+y) / (i+2);
				if (p < q and p%2 == q%2) ans++;
			}
			if (i*i == x-y) continue;
			int j = (x-y)/i;
			if ((x+y) % (j+2) == 0) {
				int p = (x-y) / j; int q = (x+y) / (j+2);
				if (p < q and p%2 == q%2) ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}
0