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 ...
随机推荐
- C#利用System.Net发送邮件
啥也不说了,直接上干货 using System.Net.Mail;using System.Net; //使用发送邮件的邮箱 var emailAcount = "826217795@qq ...
- mysql高可用架构 -> MHA部署-04
MHA架构图 本次MHA的部署基于GTID复制成功构建,普通主从复制也可以构建MHA架构. 下载所需的软件包 mkdir /server/tools -p //创建存放包的目录 [root@db01 ...
- 20 Organizing Go code 组织go代码
Organizing Go code 16 August 2012 Introduction Go code is organized differently to that of other lan ...
- angular 如何使用第三方组件ng-bootstrap
1.在你的项目中以下指令 npm install --save @ng-bootstrap/ng-bootstrap 安装完成会显示 + @ng-bootstrap/ng-bootstrap@1 ...
- tftp的安装
下载并且安装软件xinetd tftp tftpd sudo apt-get install xinetd tftp tftpd 在/etc/xinetd.d/下建立一个配置文件tftp sudo v ...
- GitHub在线创建文件夹
点击New files按钮,然后输入含有slash字符(“/”)的文件名即可.也就是建立一个含有路径(目录)的文件,即会自动产生新文件夹. 点击Upload files按钮,然后直接把本地的文件夹(内 ...
- 【LOJ】#2289. 「THUWC 2017」在美妙的数学王国中畅游
题解 我们发现,题目告诉我们这个东西就是一个lct 首先,如果只有3,问题就非常简单了,我们算出所有a的总和,所有b的总和就好了 要是1和2也是多项式就好了--其实可以!也就是下面泰勒展开的用处,我们 ...
- 黑马程序员_java基础笔记(03)...面向对象
—————————— ASP.Net+Android+IOS开发..Net培训.期待与您交流!—————————— 1:面向对象的概念,2 : 类和对象的关系,3 : 封装,4 : 构造函数,5 : ...
- CentOS源码安装搭建LNMP全过程(包括nginx,mysql,php,svn)
服务器环境为:CentOS6.5 64位 目标:搭建LNMP(Linux + Nginx + MySQL + PHP +SVN),其中svn是用来代替ftp,方便开发中调试同步代码 相关目录:所有软件 ...
- mysql (主从复制)(proxy , Amoeba)
原址如下: http://heylinux.com/archives/1004.html Mysql作为目前世界上使用最广泛的免费数据库,相信所有从事系统运维的工程师都一定接触过.但在实际的生产环境中 ...