Codeforces Round #102 (Div. 1) A. Help Farmer 暴力分解

A. Help Farmer

题目连接:

http://www.codeforces.com/contest/142/problem/A

Description

Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored A·B·C hay blocks and stored them in a barn as a rectangular parallelepiped A layers high. Each layer had B rows and each row had C blocks.

At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (A - 1) × (B - 2) × (C - 2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1 × 1 × 1 blocks and scattered them around the barn. After the theft Sam counted n hay blocks in the barn but he forgot numbers A, B и C.

Given number n, find the minimally possible and maximally possible number of stolen hay blocks.

Input

The only line contains integer n from the problem's statement (1 ≤ n ≤ 109).

Output

Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves.

Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

Sample Input

4

Sample Output

28 41

Hint

题意

给你一个n,说这个n等于(A-1)(B-2)(C-2)

然后你要找到ABC-n的最大值和最小值

题解:

自己暴力分解n之后,枚举因子k

然后再枚举n/k的因子

这样就可以得到(A-1)(B-2)(C-2)这三个玩意儿了

然后暴力统计答案就好了。

复杂度感觉是n^3/4的,但是实际跑的很快

代码

#include<bits/stdc++.h>
using namespace std;int main()
{long long n;cin>>n;long long ans1 = 0;long long ans2 = 1LL<<60;for(int i=1;i*i<=n;i++){if(n%i==0){long long p = n/i;for(int j=1;j*j<=p;j++){if(p%j==0){long long a = i;long long b = j;long long c = p/j;ans1 = max(ans1,(a+1)*(b+2)*(c+2));ans1 = max(ans1,(a+2)*(b+1)*(c+2));ans1 = max(ans1,(a+2)*(b+2)*(c+1));ans2 = min(ans2,(a+1)*(b+2)*(c+2));ans2 = min(ans2,(a+2)*(b+1)*(c+2));ans2 = min(ans2,(a+2)*(b+2)*(c+1));}}}}cout<<ans2-n<<" "<<ans1-n<<endl;
}

转载于:https://www.cnblogs.com/qscqesze/p/5578495.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/374537.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

电力电子、电机控制系统的建模和仿真_清华团队研发,首款国产电力电子仿真软件来啦~已捐赠哈工大、海工大、清华使用!...

点击上方电气小青年&#xff0c;关注并星标由于微信改版&#xff0c;只有星标才能及时看到我们的消息哦━━━━━━推荐阅读&#xff1a;《膜拜大神&#xff01;清华大学电机系2021年接收推荐免试直硕(博)生拟录取名单公示&#xff01;》《滴滴程序员年薪80万被鄙视不如在二本…

JVM如何处理锁

当我们谈论最新版本的Sun Hotspot Java虚拟机1.6时&#xff0c;当您尝试从java.util.concurrent.locks.Lock实现获取锁或输入同步块时&#xff0c;JVM将执行以下三种锁类型&#xff1a; 有偏见的 &#xff1a;有时即使在并发系统中也没有争用&#xff0c;并且在这种情况下&…

基于node.js及express实现中间件,实现post、get

首先&#xff0c;当然是有必要的环境&#xff0c;安装node&#xff0c;这个我就不多说了。 依赖模块&#xff1a; "express": "^4.13.4", "request": "^2.72.0", "body-parser": "^1.13.3",页面 $.ajax({type: &q…

可视化分析之图表选择

转载于:https://www.cnblogs.com/yymn/p/4783631.html

定义并调用函数输出 fibonacci 序列_科学网—Zmn-0351 薛问天:再谈数学概念的定义,评新华先生《0345》...

Zmn-0351 薛问天&#xff1a;再谈数学概念的定义&#xff0c;评新华先生《0345》【编者按。下面是薛问天先生发来的文章。是对《Zmn-0345》新华先生文章的评论。现在发布如下&#xff0c;供网友们共享。请大家关注并积极评论。另外本《专栏》重申&#xff0c;这里纯属学术讨论&…

Java和内存泄漏

总览 术语“内存泄漏”在Java中的使用方式不同于在其他语言中使用的方式。 通用术语中的“内存泄漏”是什么意思&#xff0c;在Java中如何使用&#xff1f; 维基百科的定义 当计算机程序消耗内存但无法将其释放回操作系统时&#xff0c;就会发生计算机科学中的内存泄漏&#x…

453. 最小操作次数使数组元素相等

给你一个长度为 n 的整数数组&#xff0c;每次操作将会使 n - 1 个元素增加 1 。返回让数组所有元素相等的最小操作次数。 class Solution {public int minMoves(int[] nums) {int res 0;int sum 0;int n nums.length;for(int i 0;i<n;i){sum nums[i];}res sum - min…

第二章 TCP/IP 基础知识

第二章 TCP/IP 基础知识 TCP/IP transmission control protocol and ip internet protocol 是互联网众多通信协议中最为著名的。 2.2 TCP/IP 的标准化 2.2.2 TCP/IP 标准化精髓 TCP/IP 协议始终具有很强的实用性。 相比于TCP/IP &#xff0c;OSI 之所以未能达到普及&#xff0…

CSS太阳月亮地球三角恋旋转效果

纯粹玩一下&#xff0c;好像没有什么实际的卵用&#xff0c;but&#xff0c;纯玩买不了上当&#xff0c;纯玩买不了受骗。。。。。。。。 地月旋转的一个css效果&#xff0c;无聊玩玩&#xff0c;可以复制到记事本试试 <!DOCTYPE html><html lang"en">&l…

gorm preload 搜索_LeetCode刷题笔记|95:不同的二叉搜索树 II

题目描述给定一个整数 n&#xff0c;生成所有由 1 ... n 为节点所组成的 二叉搜索树 。示例输入&#xff1a;3输出&#xff1a;[[1,null,3,2],[3,2,null,1],[3,1,null,null,2],[2,1,3],[1,null,2,null,3]]解释&#xff1a;以上的输出对应以下 5 种不同结构的二叉搜索树&#xf…

Java初学者指南

Java编程的第一步。 对于Java中的入门教程&#xff0c;请参阅Sun的官方帮助这里 除了核心语言外&#xff0c;还有几种技术和API 介绍。 我们建议首先阅读涵盖 基础知识&#xff0c;并继续其余的教程。 我们建议&#xff1a; 保持代码简单易读 拆分逻辑组件&#xff08;类…

Javascript中Promise对象的实现

http://segmentfault.com/a/1190000000684654 http://www.infoq.com/cn/news/2011/09/js-promise/转载于:https://www.cnblogs.com/zuiyirenjian/p/4787864.html

字符串分割与存入List集合

List<string> namelist new List<string>(); string[] namejh null; string name "张三李四王五"; 第一步&#xff1a;将三个名字分离出来 namejh name.Split("".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); namelist new Li…

GTJ2018如何导出全部工程量_如何成为优秀的造价员?广联达编制内刊手册,造价员算量高手秘籍...

如何成为优秀的造价员&#xff1f;广联达编制内刊手册&#xff0c;造价员算量高手秘籍[高手秘籍]是广联达课程编制委员会暨直播委员会精心打造的&#xff0c;能够“让您深入理解软件计算、设置等原理,遇到问题有处理思路,以常见问题为导向&#xff0c;重点进行原因分析&#xf…

带有Spring,Hibernate,Akka,Twitter Bootstrap,Apache Tiles和jQuery的Maven Web项目Kickstarter代码库...

我很高兴将第二个项目上传到GitHub&#xff0c;以帮助人们尽快开始Java Web App开发。 我正在与Apache License 2.0共享此代码。 这是相同的网址&#xff1a; https://github.com/ykameshrao/spring-hibernate-springdata-springmvc-maven-project-framework 该项目包括以下部…

git项目添加.gitigore文件

以前一直没有注意这个文件&#xff0c;最近读到了黄勇的《架构探险》&#xff0c;觉得这个文件还是很有用的。 .gitigore文件可以自己配置。 我使用的是书中所用的配置&#xff0c;简洁明了。 # Maven # target/#log# logs/# IDEA # .idea/ *.iml# Eclipse # .settings/ .metad…

463. 岛屿的周长

给定一个 row x col 的二维网格地图 grid &#xff0c;其中&#xff1a;grid[i][j] 1 表示陆地&#xff0c; grid[i][j] 0 表示水域。 网格中的格子 水平和垂直 方向相连&#xff08;对角线方向不相连&#xff09;。整个网格被水完全包围&#xff0c;但其中恰好有一个岛屿&a…

C++服务器设计(七):聊天系统服务端实现

在之前的章节中&#xff0c;我们对服务端系统的设计实现原理进行了剖析&#xff0c;在这一章中&#xff0c;我们将对服务端框架进行实际运用&#xff0c;实现一款运行于内网环境的聊天系统。该聊天系统由客户端与服务器两部分组成&#xff0c;同时服务端通过数据库维护用户的账…

高校实验室管理系统_史上最全面的实验室信息管理系统(LIMS)全解

1. LIMS的基本概念和发展状况1.1 概括LIMS实验室管理系统是为实验、检测等业务板块提供流程化、模块化、标准化操作管理系统&#xff0c;打造基于行业法规的实验室全流程质量控制管理系统&#xff0c;实现实验室“人、机、料、法、环”关键环节管理。1.2 发展状况随着科研规范化…

ORM问题

在过去的几年中&#xff0c;像Hibernate这样的对象关系映射工具已经帮助开发人员在处理关系数据库方面取得了巨大的生产力增长。 ORM使开发人员可以将精力集中在应用程序逻辑上&#xff0c;并避免为诸如插入或查询之类的简单任务编写大量样板SQL。 但是&#xff0c;充分证明的对…