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

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

  1. Codeforces Round #323 (Div. 1) B. Once Again... 暴力

    B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...

  2. Codeforces Round #359 (Div. 2) C. Robbers' watch 暴力枚举

    题目链接 题意是真的烦,到最后才知道是n个m其实就是限定表的两个时区的位数,所以所当数不够填满时区的时候前边自动补零 思路:首先来说不能有重复的数字的话,小时和分钟的总位数大于7肯定不行. 7的7次方 ...

  3. Codeforces Round #552 (Div. 3) E. Two Teams 暴力+双向链表

    传送 题意:将n个人分成2个队,每次选取队伍中未被选取的最大值,然后顺便选取左边相邻的k个数(有多少拿多少) 问你最后队伍的分配情况. #include<bits/stdc++.h>usi ...

  4. 【CF比赛】Educational Codeforces Round 102 (Rated for Div. 2)

    题目来源 Educational Codeforces Round 102 (Rated for Div. 2) A. Replacing Elements 只要判断最大值是否小于等于d,或者第一个值 ...

  5. Codeforces Round #741 (Div. 2) D2. Two Hundred Twenty One (hard version) 前缀和 + 分段模型

    传送门 文章目录 题意: 思路: 题意: 给你一个长度为nnn的串,+++代表111,−-−代表−1-1−1,让后有qqq个询问,每次询问[l,r][l,r][l,r]区间,将这段区间的数拿出来,设为 ...

  6. Codeforces Round #257 (Div. 2)

    Codeforces Round #257 (Div. 2) https://codeforces.com/contest/450/ A 模拟 1 #include<bits/stdc++.h& ...

  7. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  8. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  9. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

最新文章

  1. 艾伟:控件之ViewState
  2. 计算机等级考试三级数据库考点,全国计算机等级考试辅导:三级数据库考点
  3. 快速判断二叉树先序遍历 后序遍历
  4. 如何批量生成Code 128条形码
  5. sparksql 与flinksql 建表 与 连表记录
  6. 海信电视 android,海信聚好看app下载 海信聚好看(电视微助手) for Android V5.7.0.9 安卓手机版 下载-脚本之家...
  7. 《岳阳楼记》古文鉴赏
  8. android手机无法root成功,安卓手机不能ROOT怎么办
  9. iOS HomeKit Quick Start iOS HomeKit快速入门 Lynda课程中文字幕
  10. CircleImageView用法及源码解析(雷惊风)
  11. nRF keil工程错误相关
  12. TensorFlow简单实例(二):logistic regression
  13. PGL图学习之图神经网络ERNIESage、UniMP进阶模型[系列八]
  14. TexturePacker导入unity后图片还是显示成整图
  15. 魔兽世界自建服务器,魔兽世界怀旧服服务器选择 选哪个服务器好
  16. mybatisPlus 自定义sqlSessionFactory sql注入器失效 Invalid bound statement (not found): insertBatchSomeColumn
  17. 企业工作总结汇报PPT模板
  18. 做好的html 怎么上传到服务器上,怎么上传网页?怎样将做好的网页上传到服务器上?...
  19. 新闻速递|伦敦帝国理工学院大刀阔斧改革科研成果转化机制
  20. 花开彼岸天:我的2017年终总结

热门文章

  1. WinForm - 两个窗体之间的方法调用
  2. 埃氏筛法的一般写法(区间筛法)
  3. 进程的创建与可执行程序的加载
  4. oracle中sql语句的优化(转帖)
  5. postgresql 比较两个时间差大于 N个小时
  6. 汽车电子专业知识篇(二十)-深度解析CAN FD与传统CAN的差异
  7. 四川高职计算机二本线学校,全网首发!四川省本科二批次2019年对口高职投档录取线出炉...
  8. matlab 值法确定各指标权重,Matlab学习系列19. 熵值法确定权重
  9. 《鸿蒙理论知识06》HarmonyOS概述之应用开发基础知识
  10. java servlet jsp javabean关系图,一个关于javaBean+servlet+jsp的MVC架构有关问题