[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
题目描述
小蓝有一个超大的仓库,可以摆放很多货物。
现在,小蓝有 nn 箱货物要摆放在仓库,每箱货物都是规则的正方体。小蓝规定了长、宽、高三个互相垂直的方向,每箱货物的边都必须严格平行于长、宽、高。
小蓝希望所有的货物最终摆成一个大的长方体。即在长、宽、高的方向上分别堆 LL、WW、HH 的货物,满足 n = L \times W \times
Hn=L×W×H。
给定 nn,请问有多少种堆放货物的方案满足要求。
例如,当 n = 4n=4 时,有以下 66 种方案:1×1×4、1×2×2、1×4×1、2×1×2、2 × 2 × 1、4 × 1 ×
11×1×4、1×2×2、1×4×1、2×1×2、2×2×1、4×1×1。
请问,当 n = 2021041820210418n=2021041820210418 (注意有 1616 位数字)时,总共有多少种方案?
提示:建议使用计算机编程解决问题。
答案提交
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
运行限制
* 最大运行时间:1s
* 最大运行内存: 256M
三重暴力确实是个办法,但是时间复杂度太高,肯定不行
那么只循环前两个变量,第三个变量用maxn/a/b计算(需要同时判断是否能除尽)
这种方法同样跑不起来,也不推荐
所以我们要进行合理的剪枝
我们不妨用组合的办法做
剪枝条件如下:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll
maxn=2021041820210418; ll a,b,c,ans; bool check(int x) { if(maxn%x==0) return
true; else return false; } bool check2() { if(maxn%(a*b)==0) return true; else
return false; } int main() { for(a=1;a*a*a<=maxn;a++) { if(check(a)) {
for(b=a;a*b*b<=maxn;b++) { if(check2()) { c=maxn/(a*b); printf("%lld %lld
%lld\n",a,b,c); if(a==b&&a==c) ans+=1; else if(a==b||a==c||b==c) ans+=3; else
ans+=6; } } } } cout<<ans; return 0; }
三个数相同,排列有1种
两个数相同,排列有3种
都不相同,排列有6种