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. mini2440的程序下载

    mini2440拿到手有四天了,抱着很大的兴趣看韦东山老师的视频,但是因为电脑是win7 64bit的系统,dnw的驱动没有,经查询可以使用supervivi,就查找相关的资料.但是始终弄不好,后来使 ...

  2. Linux input子系统学习总结(三)----Input设备驱动

    Input 设备驱动 ---操作硬件获取硬件寄存器中设备输入的数据,并把数据交给核心层: 一 .设备驱动的注册步骤: 1.分配一个struct  input_dev :          struct ...

  3. MySQL 高可用:mysql+Lvs+Keepalived 负载均衡及故障转移

    系统信息: mysql主库 mysql从库 VIP 192.168.1.150 mysql 主主同步都设置 auto-increment-offset,auto-increment-increment ...

  4. 芒果TV 视频真实的地址获取

    # coding=utf-8 import requests import json import re import os import urlparse import random vid = r ...

  5. ggplot2使用初探

    ggplot2已经成为了R语言中数据可视化的同义词, 这是一个强大的工具, 可以帮助我们制作优良的图表, 创造出令人吃惊的图片, 下面我们一起学习(本博文参考了知乎问题如何使用 ggplot2中黄宝臣 ...

  6. Python列表(list)

    序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. 此外,Python已经内置确定序列的长度以及确定最大和最小的元素 ...

  7. spark和hadoop比较

    来源知乎 计算模型:hadoop-MapReduce,Spark-DAG(有向无环图)评注:经常有人说Spark就是内存版的MapReduce,实际上不是的.Spark使用的DAG计算模型可以有效的减 ...

  8. GBDT+LR simple例子

    卧槽,本来猜GBDT获取的组合特征,需要自己去解析GBDT的树,scikit learn里面竟然直接调用apply函数就可以了 # 弱分类器的数目 n_estimator = 10 # 随机生成分类数 ...

  9. window时间同步机制的简单介绍

    1 window自身现在采用w32tm程序来进行时间校正,window自身携带NTP程序,但默认下时关闭的,默认的NTP时客户端. 2 w32tm时用来代替早期的时钟同步程序net  time 3 w ...

  10. 编译环境搭建:Makefile

    前言 长久以来,笔者一直想用一种管理工具,将所编写的测试程序.算法代码以及工程代码统一管理起来.因为有些是用Java写的有些是用C++写的.虽有想法,但却无行动.这又让我想起了昨天晚上看到一部电影里所 ...