2020 Winter Holiday [gmoj2174] [Building block] [Simulation, Math]

Title description

Weiwei has an A × B × C rectangular volume, and the blocks are composed of 1 × 1 × 1 small blocks. We set the height of this cuboid to A, the width to B, and the length to C. (For convenience, the length of the cuboid does not have to be larger than the width).
Now Weiwei has dug a (A-1) × (B-2) × (C-2) small cuboid in the upper left corner of this cuboid. And tell you that the volume of the cuboid being dug is n, that is, n = (A-1) × (B-2) × (C-2). Now I ask you, after the small cuboid is dug out, what are the minimum and maximum number of small 1 × 1 × 1 blocks left in the original rectangular volume? In other words, on the premise of telling you the value of n, find min {A × B × Cn} and max {A × B × Cn}.

Input

The input file is named block.in.
Enter a total of 1 line, only a positive integer n.

Output

The output file is named block.out.
The output line consists of two positive integers separated by spaces, which in turn represent the minimum number of remaining small blocks and the maximum number of remaining small blocks.

Sample input

[Sample input 1]
4

[Sample input 2]
7

Sample output

[Sample output 1]
28 41

[Sample output 2]
47 65

Data range limitation

For 100% of data 1 ≤ n ≤ 10 ^ 9

prompt

Explanation of Sample 1:
4 = (2-1) × (4-2) × (4-2) The minimum remaining small building block is 2 × 4 × 4-4 = 28 (in this case, the values ​​of A, B and C are respectively It is 2,
4, 4) 4 = (5-1) × (3-2) × (3-2) The most remaining small blocks are 5 × 3 × 3-4 = 41 (at this time A, B, C Values ​​are 5, 3, and 3)

analysis

In fact, we can find c by enumerating a and b, which can save one dimension. Just add some ringing.

Code on

#include<iostream>
#include<cstdio>
using namespace std;
long long n,mn=2147483647,mx,c;
int main()
{
	freopen("block.in","r",stdin);
	freopen("block.out","w",stdout);
	cin>>n;
	for(int a=1;a*a*a<=n;a++) //优化
	{
		if(n%a==0) //判断整除
		{
			for(int b=a;a*b*b<=n;b++)//优化 
			{
				if(n/a%b==0)
			    {
			  		c=n/a/b;//知道a,b就知道c 
			  		if(a*b*c==n)//所有情况 
			  		{
			   		    mn=min((a+1)*(b+2)*(c+2),mn);
						mn=min((a+2)*(b+1)*(c+2),mn);
					    mn=min((a+2)*(b+2)*(c+1),mn);
					    mx=max((a+1)*(b+2)*(c+2),mx);
					    mx=max((a+2)*(b+1)*(c+2),mx);
					    mx=max((a+2)*(b+2)*(c+1),mx);
			  		}
			    }
			}
		}
	} 
	cout<<mn-n<<" "<<mx-n;
	return 0;
}


Published 110 original articles · won 100 · visited 8037

Guess you like

Origin blog.csdn.net/dglyr/article/details/104803872