第十二届蓝桥杯省赛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;
}
相关推荐
华清远见成都中心12 分钟前
C 语言内存管理深度解析:malloc/free 与嵌入式堆栈分配策略
java·c语言·算法
怕什么真理无穷15 分钟前
C++面试5_ TCP 粘包2(工业级)
开发语言·c++·tcp/ip
努力努力再努力wz20 分钟前
【MySQL 进阶系列】拒绝滥用root:从 mysql.user 到权限校验,带你彻底理解用户管理与授权机制!
android·c语言·开发语言·数据结构·数据库·c++·mysql
雪度娃娃32 分钟前
基于TCP的网络词典
网络·c++·tcp/ip·c#
炸膛坦客1 小时前
嵌入式 - 数据结构与算法:(1-4)数据结构 - 单链表的两个核心缺点(引入循环/双向链表)
c语言·数据结构·链表
春蕾夏荷_7282977251 小时前
2、c++ acl tcp服务器客户端简单实例-服务器端(1)
服务器·c++·tcp/ip
墨染千千秋1 小时前
C++if判断的使用全解
c++
雪度娃娃1 小时前
设计模式——单例模式
开发语言·c++·设计模式
Lenyiin1 小时前
《LeetCode 顺序刷题》61 - 70
java·c++·python·算法·leetcode·lenyiin
想唱rap2 小时前
应用层HTTPS协议
服务器·网络·c++·网络协议·http·https