結果

問題 No.1626 三角形の構築
ユーザー chocoruskchocorusk
提出日時 2021-07-23 22:44:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 2,291 bytes
コンパイル時間 3,978 ms
コンパイル使用メモリ 203,124 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 15:47:08
合計ジャッジ時間 6,512 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 44 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 29 ms
4,380 KB
testcase_08 AC 50 ms
4,380 KB
testcase_09 AC 66 ms
4,380 KB
testcase_10 AC 49 ms
4,376 KB
testcase_11 AC 59 ms
4,380 KB
testcase_12 AC 20 ms
4,380 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 36 ms
4,380 KB
testcase_15 AC 20 ms
4,376 KB
testcase_16 AC 41 ms
4,380 KB
testcase_17 AC 37 ms
4,376 KB
testcase_18 AC 18 ms
4,380 KB
testcase_19 AC 36 ms
4,376 KB
testcase_20 AC 51 ms
4,376 KB
testcase_21 AC 35 ms
4,376 KB
testcase_22 AC 65 ms
4,380 KB
testcase_23 AC 40 ms
4,376 KB
testcase_24 AC 365 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll, int> P;

int main()
{
    int T; cin>>T;
    while(T--){
        ll s, t;
        cin>>s>>t;
        if(16*s*s%t!=0){
            cout<<0<<endl;
            continue;
        }
        map<ll, int> mp;
        ll s1=s, t1=t;
        for(ll p=2; p*p<=s1; p++){
            if(s1%p==0){
                while(s1%p==0){
                    s1/=p;
                    mp[p]+=2;
                }
            }
        }
        if(s1>1) mp[s1]+=2;
        mp[2]+=4;
        for(ll p=2; p*p<=t1; p++){
            if(t1%p==0){
                while(t1%p==0){
                    t1/=p;
                    mp[p]--;
                }
            }
        }
        if(t1>1) mp[t1]--;
        vector<P> f;
        for(auto p:mp) f.push_back(p);
        vector<ll> v;
        auto dfs=[&](auto dfs, ll x, int k)->void{
            if(k==f.size()){
                if(t>x && (t-x)%2==0){
                    v.push_back(x);
                }
                return;
            }
            ll p=f[k].first, x1=x;
            for(int i=0; i<=f[k].second; i++){
                if(x1<t) dfs(dfs, x1, k+1);
                x1*=p;
            }
        };
        dfs(dfs, 1, 0);
        ll u=16*s*s/t;
        vector<pair<pair<ll, ll>, ll>> ans;
        for(auto x:v){
            for(auto y:v){
                if(u/x%y!=0 || (t-u/x/y)%2!=0) continue;
                ll a=(t-x)/2, b=(t-y)/2, c=(t-u/x/y)/2;
                if(c>0 && a+b+c==t && a<=b && b<=c && c<=1000000000){
                    ans.push_back({{a, b}, c});
                }
            }
        }
        cout<<ans.size()<<endl;
        for(auto q:ans) cout<<q.first.first<<" "<<q.first.second<<" "<<q.second<<endl;
    }
    return 0;
}
0