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;
}

Codeforces Round #102 (Div. 1) A. Help Farmer 暴力分解的更多相关文章

  1. Codeforces Round #102 (Div. 2) 题解

    A. 解一个方程. 还是厚颜无耻地暴力吧~ #include <iostream> using namespace std; int r1, r2, c1, c2, d1, d2; boo ...

  2. Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心

    题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...

  3. Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力

    C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerb ...

  4. Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)

    题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...

  5. Codeforces Round #192 (Div. 1) B. Biridian Forest 暴力bfs

    B. Biridian Forest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/pr ...

  6. Codeforces Round #277 (Div. 2) D. Valid Sets 暴力

    D. Valid Sets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem ...

  7. Codeforces Round #326 (Div. 2) B. Duff in Love 分解质因数

    B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/proble ...

  8. 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 ...

  9. Codeforces Round #323 (Div. 2) C. GCD Table 暴力

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

随机推荐

  1. mysql -> 用户管理&数据类型_04

    用户权限,回收权限 数据类型 生产案例

  2. RestTemplate中文乱码问题(spring-web3.0.7版本)

    从网上找的方法: 方法一: //resttemplate乱码问题 //3.1.X以上版本使用 // restTemplate.getMessageConverters().add(0, StringH ...

  3. CSS--布局模型,颜色值,长度值

    目录 布局模型 流动模型(Flow) 浮动模型 (Float) 层模型(Layer) 颜色值 长度值  一.布局模型 网页布局模型:个人理解,就是对html中各个元素进行一个排列.而排列的方法可以分为 ...

  4. Android Studio配置opencv

    安装过程参考:http://www.cnblogs.com/tail/p/4618476.html demo参考:http://blog.csdn.net/gao_chun/article/detai ...

  5. VS Code折腾记 - (3) 多图解VSCode基础功能

    前言 想了想,对于一个刚接触VSCODE的人来说,有什么比图片更通俗易懂的呢? 启动界面 : 快捷键(Ctrl + Shift + E) Search && replace : 快捷键 ...

  6. 为通过 ATS 检测 Tomcat 完全 TLS v1.2、完全正向加密及其结果检验

    2017 年起 app store 要求 app 对接的服务器支持 TLS v1.2,否则 ats 检测不予通过.有点强制推 TLS v1.2 的意味.本文介绍如何使 tomcat 强制执行 TLS ...

  7. C#比较时分秒大小,终止分钟默认加十分钟,解决跨天、跨月、跨年的情况

    private void cmbInHostimes_SelectedIndexChanged(object sender, EventArgs e) { DataRow[] dr; if (chkM ...

  8. javascript重要类方法笔记

    三.数据结构和map    1.大括号数据结构:{}        1.1 键值对形式,类似Map           1.2 var treeNode={};            treeNode ...

  9. 选择性卸载eclipse安装过的工具

    我们有时候需要卸载eclipse中之前安装的一些工具,而不想全部删除,那就可以采取下面的方式: 打开eclipse,Help->About Eclipse->Installation De ...

  10. WebApi 插件式构建方案:集成加载数据库连接字符串

    body { border: 1px solid #ddd; outline: 1300px solid #fff; margin: 16px auto; } body .markdown-body ...