結果
| 問題 |
No.1200 お菓子配り-3
|
| コンテスト | |
| ユーザー |
tanimani364
|
| 提出日時 | 2020-08-29 13:37:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,231 bytes |
| コンパイル時間 | 2,370 ms |
| コンパイル使用メモリ | 200,172 KB |
| 最終ジャッジ日時 | 2025-01-13 20:11:53 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 WA * 7 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
ll gcd(ll n, ll m)
{
ll tmp;
while (m != 0)
{
tmp = n % m;
n = m;
m = tmp;
}
return n;
}
ll lcm(ll n, ll m)
{
return abs(n) / gcd(n, m) * abs(m); //gl=xy
}
using namespace std;
ll x,y;
bool check(ll a,ll b,ll c){
return x-a*b==c&&y-a*c==b;
}
#define int ll
using P=pair<int,int>;
void solve(){
int t;
cin>>t;
while(t--){
cin>>x>>y;
set<pair<int,pair<int,int>>>st;
ll ans=0;
if(x==y){
for(ll b=1;b<=x-1;++b){
if(!st.count(pair<int,P>(1,P(b,x-b)))){
++ans;
st.emplace(1,P(b,x-b));
}
}
}
for(ll a=2;a*a<=max(x,y)+1;++a){
if((a*x-y)%(a*a-1))continue;
ll b=(a*x-y)/(a*a-1),c=x-a*b;
if(b>0&&c>0){
if(check(a,b,c)&&!st.count(pair<int,P>(a,P(b,c)))){
++ans;
st.emplace(a,P{b,c});
}
if(check(b,a,c)&&!st.count(pair<int,P>(b,P(a,c)))){
++ans;
st.emplace(b,P{a,c});
}
if(check(a,c,b)&&!st.count(pair<int,P>(a,P(c,b)))){
++ans;
st.emplace(a,P{c,b});
}
if(check(b,c,a)&&!st.count(pair<int,P>(b,P(c,a)))){
++ans;
st.emplace(b,P{c,a});
}
if(check(c,a,b)&&!st.count(pair<int,P>(c,P(a,b)))){
++ans;
st.emplace(c,P{a,b});
}
if(check(c,b,a)&&!st.count(pair<int,P>(c,P(b,a)))){
++ans;
st.emplace(c,P{b,a});
}
}
}
// for(auto x:st){
// cout<<x.first<<" "<<x.second.first<<" "<<x.second.second<<"\n";
// }
cout<<ans<<"\n";
}
}
#undef int
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(15);
solve();
return 0;
}
tanimani364