日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #102 (Div. 1) A. Help Farmer 暴力分解

發布時間:2023/12/1 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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; }

轉載于:https://www.cnblogs.com/qscqesze/p/5578495.html

總結

以上是生活随笔為你收集整理的Codeforces Round #102 (Div. 1) A. Help Farmer 暴力分解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。