第十二届蓝桥杯省赛C&C++ 研究生组-货物摆放

还是整数分解问题,注意n本身也是约数

cpp 复制代码
#include <iostream>
int main(){
  printf("2430");
  return 0;
}
cpp 复制代码
#include <iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll n = 2021041820210418LL;
const ll maxn = 44955998;
ll p[maxn] = {1};
int main(){
  ll sqr = (ll) sqrt(n), count = 0, num = 1;//126432 44955998
  for(int i = 2; i <= sqr; i++){
  	if(n % i == 0){
  		p[num++] = i;
  		if(i * i != n) p[num++] = n / i;
	  }
  }
  p[num] = n;	
  for(int i = 0; i <= num; i++){
  	for(int j = 0; j <= num; j++){
  		for(int k = 0; k <= num; k++){
  			if(p[i]*p[j]*p[k] == n) {
  				count++;
  				printf("%lld %lld %lld\n", p[i], p[j], p[k]);
			  }
		  }
	  }
  }
  printf("%lld", count);
  return 0;
}
相关推荐
我不会插花弄玉4 小时前
13.多路转接epoll【由浅入深-网络】
网络·c++·epoll
郝学胜-神的一滴6 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
西西弗Sisyphus7 小时前
C++ explicit 关键字工程实践
开发语言·c++
戊本菌8 小时前
进程(三)进程优先级:谁先上 CPU
linux·c语言·硬件架构
AIgorithmGEEK9 小时前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set
嵌入式 Linux手记11 小时前
一块内存,三种解释:union 的真实用法
linux·c语言·驱动开发·嵌入式
一拳一个呆瓜12 小时前
【STL】头文件:<cmath>
c++·stl
草莓熊Lotso12 小时前
【C++ 基于微服务的即时通讯系统】ElasticSearch 用户数据管理实现
linux·数据库·c++·elasticsearch·微服务·架构
慧都产品智能化12 小时前
Qt 开发 CAD/CAM 工序表的隐性成本分析
c++·qt·qt5·qt6.3
eggwyw14 小时前
linux下的C\C++多进程多线程编程实例详解
开发语言·c++