結果

問題 No.1200 お菓子配り-3
ユーザー cn_449cn_449
提出日時 2020-08-28 21:55:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 829 ms / 4,000 ms
コード長 2,212 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 133,048 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 23:45:48
合計ジャッジ時間 8,470 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 6 ms
6,944 KB
testcase_08 AC 7 ms
6,940 KB
testcase_09 AC 7 ms
6,940 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 7 ms
6,944 KB
testcase_12 AC 50 ms
6,940 KB
testcase_13 AC 51 ms
6,944 KB
testcase_14 AC 51 ms
6,940 KB
testcase_15 AC 51 ms
6,944 KB
testcase_16 AC 50 ms
6,944 KB
testcase_17 AC 179 ms
6,940 KB
testcase_18 AC 255 ms
6,944 KB
testcase_19 AC 62 ms
6,944 KB
testcase_20 AC 510 ms
6,940 KB
testcase_21 AC 500 ms
6,944 KB
testcase_22 AC 598 ms
6,944 KB
testcase_23 AC 507 ms
6,944 KB
testcase_24 AC 500 ms
6,944 KB
testcase_25 AC 502 ms
6,940 KB
testcase_26 AC 503 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 829 ms
6,940 KB
testcase_29 AC 609 ms
6,940 KB
testcase_30 AC 611 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int t;
	cin >> t;
	while (t--) {
		int x, y;
		cin >> x >> y;
		int sum = x + y;
		if (x == y) {
			int ans = x - 1;
			if (x % 2 == 0) ans--;
			vector<int> check;
			for (int i = 1; i * i <= x; i++) {
				if (x % i == 0) {
					check.pb(i);
					if (i * i != x) check.pb(x / i);
				}
			}
			for (int b : check) {
				int a = x / b - 1;
				if (a > 0) ans++;
			}
			cout << ans << '\n';
		}
		else {
			if (x < y) swap(x, y);
			int ans = 0;
			vector<int> check;
			for (int i = 1; i * i <= sum; i++) {
				if (sum % i == 0) {
					check.pb(i);
					if (i * i != sum) check.pb(sum / i);
				}
			}
			for (int i : check) {
				if (i <= 2) continue;
				int a = i - 1;
				if ((x - y) % (a - 1) == 0) {
					int bpc = (x + y) / (a + 1);
					int bmc = (x - y) / (a - 1);
					if ((bpc - bmc) % 2 == 1) continue;
					int b = (bpc + bmc) / 2;
					int c = (bpc - bmc) / 2;
					if (b > 0 && c > 0) ans++;
				}
			}
			cout << ans << '\n';
		}
	}
}
0