結果

問題 No.1626 三角形の構築
ユーザー auauaauaua
提出日時 2021-07-23 23:05:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 2,181 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 178,212 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 11:44:56
合計ジャッジ時間 3,240 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=3010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;

//gcd
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}

signed main(){
    ll q;cin>>q;
    while(q--){
        ll s,t;
        cin>>s>>t;
        ll x=s*s*16LL;
        if(x%t!=0){
            cout<<0<<endl;
            continue;
        }
        x/=t;
        set<vector<ll> >st;
        for(ll i=1;i*i*i<=x;i++){
            if(x%i!=0)continue;
            if(t-i<=0||(t-i)%2!=0)continue;
            ll a=(t-i)/2;
            ll X=x;
            X/=(t-2LL*a);
            ll y=sqrt(t*t-2LL*(t-a)*t-X+(t-a)*(t-a));
            if(t*t-2LL*(t-a)*t-X+(t-a)*(t-a)==y*y){
                if((t-a+y)%2==0){
                    ll b=(t-a+y)/2LL;
                    ll c=t-a-b;
                    vector<ll>z(3);
                    z[0]=a,z[1]=b,z[2]=c;
                    sort(all(z));
                    if(z[0]>0&&z[1]+z[0]>z[2]){
                        st.insert(z);
                    }
                }
                if((t-a-y)%2==0){
                    ll b=(t-a-y)/2LL;
                    ll c=t-a-b;
                    vector<ll>z(3);
                    z[0]=a,z[1]=b,z[2]=c;
                    sort(all(z));
                    if(z[0]>0&&z[1]+z[0]>z[2]){
                        st.insert(z);
                    }
                }
            }
        }
        cout<<st.size()<<endl;
        for(auto e:st){
            rep(i,3){
                cout<<e[i]<<' ';
            }
            cout<<endl;
        }
    }
}
0