結果

問題 No.1143 面積Nの三角形
ユーザー chocoruskchocorusk
提出日時 2020-08-01 00:08:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 251 ms / 800 ms
コード長 1,567 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 136,068 KB
最終ジャッジ日時 2025-01-12 12:00:48
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<pair<ll, int>> f;
ll ans;
vector<pair<pair<ll, ll>, ll>> v;
ll a[4];
void dfs(int k, ll x, ll y, ll z, ll w){
	if(k==f.size()){
		a[0]=x, a[1]=y, a[2]=z, a[3]=w;
		sort(a, a+4);
		if(a[3]==a[0]+a[1]+a[2]){
			v.push_back({{a[3]-a[2], a[3]-a[1]}, a[3]-a[0]});
		}
		return;
	}
	ll q[40]; q[0]=1;
	for(int i=0; i<f[k].second; i++) q[i+1]=q[i]*f[k].first;
	for(int i=0; i<=f[k].second; i++){
		int j1=0;
		if(k==0) j1=i;
		for(int j=j1; i+j<=f[k].second; j++){
			int l1=0;
			if(k==0) l1=j;
			for(int l=l1; i+j+l<=f[k].second; l++){
				if(k==0 && l>f[k].second-i-j-l) break;
				dfs(k+1, x*q[i], y*q[j], z*q[l], w*q[f[k].second-i-j-l]);
			}
		}
	}
}
int main()
{
	ll n; cin>>n;
	if(n==1){
		cout<<0<<endl; return 0;
	}
	ll n1=n;
	for(ll i=2; i*i<=n1; i++){
		if(n1%i==0){
			int e=0;
			while(n1%i==0){
				n1/=i; e++;
			}
			f.push_back({i, 2*e});
		}
	}
	if(n1>1) f.push_back({n1, 2});
	dfs(0, 1, 1, 1, 1);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	cout<<v.size()<<endl;
	return 0;
}
0