結果
問題 | No.1200 お菓子配り-3 |
ユーザー |
![]() |
提出日時 | 2020-08-28 21:55:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,258 ms / 4,000 ms |
コード長 | 2,212 bytes |
コンパイル時間 | 1,491 ms |
コンパイル使用メモリ | 129,592 KB |
最終ジャッジ日時 | 2025-01-13 17:18:03 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 |
ソースコード
#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';}}}