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;
}
Codeforces Round #102 (Div. 1) A. Help Farmer 暴力分解的更多相关文章
- Codeforces Round #102 (Div. 2) 题解
A. 解一个方程. 还是厚颜无耻地暴力吧~ #include <iostream> using namespace std; int r1, r2, c1, c2, d1, d2; boo ...
- Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心
题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...
- Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力
C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerb ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 从零单排Hadoop——1.搭建Hadoop开发环境
Hadoop环境准备:ubuntu 12.05.Hadoop 2.4 一.安装ssh 由于hadoop可以配置为集群运行,因此系统需要安装ssh工具保证集群中各节点可以互相访问. 获取ssh软件: s ...
- Git 创建仓库【转】
转自:http://www.runoob.com/git/git-create-repository.html Git 创建仓库 本章节我们将为大家介绍如何创建一个 Git 仓库. 你可以使用一个已经 ...
- 一步一步搭建 oracle 11gR2 rac + dg 之前传 (一)【转】
一步一步在RHEL6.5+VMware Workstation 10上搭建 oracle 11gR2 rac + dg 之前传 (一) 转自 一步一步搭建 oracle 11gR2 rac + dg ...
- 大数据系列之数据仓库Hive中分区Partition如何使用
Hive系列博文,持续更新~~~ 大数据系列之数据仓库Hive原理 大数据系列之数据仓库Hive安装 大数据系列之数据仓库Hive中分区Partition如何使用 大数据系列之数据仓库Hive命令使用 ...
- js对金额浮点数运算精度的处理方案
浮点数产生的原因 浮点数转二进制,会出现无限循环数,计算机又对无限循环小数进行舍入处理 js弱语言的解决方案 方法一: 指定要保留的小数位数(0.1+0.2).toFixed(1) = 0.3;这个方 ...
- 添加自签发的 SSL 证书为受信任的根证书
原文:http://cnzhx.net/blog/self-signed-certificate-as-trusted-root-ca-in-windows/ 添加自签发的 SSL 证书为受信任的根证 ...
- Linux学习笔记:输入输出重定向 >>命令
Linux重定向是指修改原来默认的一些东西,对原来系统命令的默认执行方式进行改变.比如说我不想看到在显示器的输出,而是希望输出到某一文件中就可以通过Linux重定向来进行这项工作. 将stdout重定 ...
- PHP array_diff 计算数组的差集
array_diff (PHP 4 >= 4.0.1, PHP 5) array_diff — 计算数组的差集 说明 array array_diff ( array $array1 , arr ...
- XML&反射
本节内容: XML DTD约束 Schema约束 dom4j解析 反射 为了实现访问不同路径(/hello)执行不同的资源(HelloMyServlet),我们需要使用XML进行配置:为了限定XML内 ...
- snmp常见操作
常用snmp OID说明下面这些值可以手动连接进行获取数据: 用zabbix监控交换机和路由器需要一款能够获取网络设备OID的工具,可用getif来获得OID 也可以使用snmpwalk 配置交换机的 ...