方法一:
将n一分为二(n=a乘以b)再将a一分为二(a=c乘以d)
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long
ll n=2021041820210418;
struct v{
ll a,b,c;
bool operator<(const v&y)const{
if(y.a==a){
if(b==y.b){
return y.c<c;
}
return y.b<b;
}
return y.a<a;
}
} ;
int main()
{
int t=0;
ll num[10000];
set<v>s;
for(int i=1;i<=n/i;i++){
if(n%i==0){
num[t++]=i;
num[t++]=n/i;
}
}
for(int i=0;i<t;i++){
for(ll j=1;j<=num[i]/j;j++){
if(num[i]%j==0){
ll a=j,b=num[i]/j,c=n/num[i],t;
s.insert({a,b,c});
s.insert({b,a,c});
}
}
}
cout<<s.size();
return 0;
}
方法二:
求出n所有的质因数
#define ll long long
ll n = 2021041820210418;
ll a[102], cnt;
struct Node {
ll l, w, h;
Node() {}
Node(ll _l, ll _w, ll _h) : l(_l), w(_w), h(_h) {}
bool operator<(const Node &y) const {
if (l == y.l) {
if (w == y.w) {
return h < y.h;
}
return w < y.w;
}
return l < y.l;
}
};
set<Node> ans;
void dfs(int p, ll l, ll w, ll h) {
if (p == cnt) {
ans.insert(Node(l, w, h));
return;
}
dfs(p + 1, l * a[p], w, h);
dfs(p + 1, l, w * a[p], h);
dfs(p + 1, l, w, h * a[p]);
}
int main() {
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
a[cnt++] = i;
n /= i;
i--;
}
}
a[cnt++] = n;
dfs(0, 1, 1, 1);
cout << ans.size() << endl;
return 0;
}