import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;
public class Main_08 {
/**
* 小蓝有一个超大的仓库,可以摆放很多货物。
* 现在,小蓝有 nn 箱货物要摆放在仓库,每箱货物都是规则的正方体。
* 小蓝规定了长、宽、高三个互相垂直的方向,每箱货物的边都必须严格平行于长、宽、高。
* 分析:n=a*b*c
* 正确答案:2430 我的答案: 2436
* BUG: a a b型只有三种排列方式 用count记录该类型
* 经过修改后: 正确答案:2430 我的答案: 2436
*/
public static void main(String[] args) {
long num=2021041820210418l;
// long num = 4;
long square_root_num = (long) Math.pow(num, 0.5);
ArrayList list_a = new ArrayList();
//储存abc的组合
HashSet<factor> factors = new HashSet<factor>();
//储存num的因子 a
for (long i = 1; i <= square_root_num; i++) {
if (num % i == 0) {
list_a.add(i);
}
}
//System.out.println(list_a);
// bc
//b
ArrayList list_b = new ArrayList();
//c
// * BUG: a a b型只有三种排列方式 用count记录该类型
int count=0;
ArrayList list_c = new ArrayList();
for (int i = 0; i < list_a.size(); i++) {
long bc = num / (long) list_a.get(i);
long square_root_bc = (long) Math.pow(bc, 0.5);
for (long j = 1; j <= square_root_bc; j++) {
if (bc % j == 0) {
factor factor = new factor((long) list_a.get(i), j, bc / j);
factors.add(factor);
if ((long) list_a.get(i)==j||(long) list_a.get(i)==bc/j||j==bc/j) {
count++;
}
}
}
}
//System.out.println(factors);
System.out.println((factors.size()-count)*6+count*3);
}
static class factor {
long a, b, c;
public factor(long a, long b, long c) {
long temp;
if (a > b) {
temp = a;
a = b;
b = temp;
}
if (b > c) {
temp = b;
b = c;
c = temp; //此时c为最大数
}
if (a > b) {
temp = a;
a = b;
b = temp;
}
this.a = a;
this.b = b;
this.c = c;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
factor factor = (factor) o;
return a == factor.a && b == factor.b && c == factor.c;
}
@Override
public int hashCode() {
return Objects.hash(a, b, c);
}
@Override
public String toString() {
return "["+a+"--"+b+"--"+c+"]";
}
}
}
【蓝桥杯】货物摆放 Java
最新推荐文章于 2022-09-01 14:44:28 发布