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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值