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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/374537.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/374537.shtml
英文地址,請注明出處:http://en.pswp.cn/news/374537.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

電力電子、電機控制系統的建模和仿真_清華團隊研發,首款國產電力電子仿真軟件來啦~已捐贈哈工大、海工大、清華使用!...

點擊上方電氣小青年&#xff0c;關注并星標由于微信改版&#xff0c;只有星標才能及時看到我們的消息哦━━━━━━推薦閱讀&#xff1a;《膜拜大神&#xff01;清華大學電機系2021年接收推薦免試直碩(博)生擬錄取名單公示&#xff01;》《滴滴程序員年薪80萬被鄙視不如在二本…

JVM如何處理鎖

當我們談論最新版本的Sun Hotspot Java虛擬機1.6時&#xff0c;當您嘗試從java.util.concurrent.locks.Lock實現獲取鎖或輸入同步塊時&#xff0c;JVM將執行以下三種鎖類型&#xff1a; 有偏見的 &#xff1a;有時即使在并發系統中也沒有爭用&#xff0c;并且在這種情況下&…

基于node.js及express實現中間件,實現post、get

首先&#xff0c;當然是有必要的環境&#xff0c;安裝node&#xff0c;這個我就不多說了。 依賴模塊&#xff1a; "express": "^4.13.4", "request": "^2.72.0", "body-parser": "^1.13.3",頁面 $.ajax({type: &q…

可視化分析之圖表選擇

轉載于:https://www.cnblogs.com/yymn/p/4783631.html

定義并調用函數輸出 fibonacci 序列_科學網—Zmn-0351 薛問天:再談數學概念的定義,評新華先生《0345》...

Zmn-0351 薛問天&#xff1a;再談數學概念的定義&#xff0c;評新華先生《0345》【編者按。下面是薛問天先生發來的文章。是對《Zmn-0345》新華先生文章的評論。現在發布如下&#xff0c;供網友們共享。請大家關注并積極評論。另外本《專欄》重申&#xff0c;這里純屬學術討論&…

Java和內存泄漏

總覽 術語“內存泄漏”在Java中的使用方式不同于在其他語言中使用的方式。 通用術語中的“內存泄漏”是什么意思&#xff0c;在Java中如何使用&#xff1f; 維基百科的定義 當計算機程序消耗內存但無法將其釋放回操作系統時&#xff0c;就會發生計算機科學中的內存泄漏&#x…

453. 最小操作次數使數組元素相等

給你一個長度為 n 的整數數組&#xff0c;每次操作將會使 n - 1 個元素增加 1 。返回讓數組所有元素相等的最小操作次數。 class Solution {public int minMoves(int[] nums) {int res 0;int sum 0;int n nums.length;for(int i 0;i<n;i){sum nums[i];}res sum - min…

第二章 TCP/IP 基礎知識

第二章 TCP/IP 基礎知識 TCP/IP transmission control protocol and ip internet protocol 是互聯網眾多通信協議中最為著名的。 2.2 TCP/IP 的標準化 2.2.2 TCP/IP 標準化精髓 TCP/IP 協議始終具有很強的實用性。 相比于TCP/IP &#xff0c;OSI 之所以未能達到普及&#xff0…

CSS太陽月亮地球三角戀旋轉效果

純粹玩一下&#xff0c;好像沒有什么實際的卵用&#xff0c;but&#xff0c;純玩買不了上當&#xff0c;純玩買不了受騙。。。。。。。。 地月旋轉的一個css效果&#xff0c;無聊玩玩&#xff0c;可以復制到記事本試試 <!DOCTYPE html><html lang"en">&l…

gorm preload 搜索_LeetCode刷題筆記|95:不同的二叉搜索樹 II

題目描述給定一個整數 n&#xff0c;生成所有由 1 ... n 為節點所組成的 二叉搜索樹 。示例輸入&#xff1a;3輸出&#xff1a;[[1,null,3,2],[3,2,null,1],[3,1,null,null,2],[2,1,3],[1,null,2,null,3]]解釋&#xff1a;以上的輸出對應以下 5 種不同結構的二叉搜索樹&#xf…

Java初學者指南

Java編程的第一步。 對于Java中的入門教程&#xff0c;請參閱Sun的官方幫助這里 除了核心語言外&#xff0c;還有幾種技術和API 介紹。 我們建議首先閱讀涵蓋 基礎知識&#xff0c;并繼續其余的教程。 我們建議&#xff1a; 保持代碼簡單易讀 拆分邏輯組件&#xff08;類…

Javascript中Promise對象的實現

http://segmentfault.com/a/1190000000684654 http://www.infoq.com/cn/news/2011/09/js-promise/轉載于:https://www.cnblogs.com/zuiyirenjian/p/4787864.html

字符串分割與存入List集合

List<string> namelist new List<string>(); string[] namejh null; string name "張三李四王五"; 第一步&#xff1a;將三個名字分離出來 namejh name.Split("".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); namelist new Li…

GTJ2018如何導出全部工程量_如何成為優秀的造價員?廣聯達編制內刊手冊,造價員算量高手秘籍...

如何成為優秀的造價員&#xff1f;廣聯達編制內刊手冊&#xff0c;造價員算量高手秘籍[高手秘籍]是廣聯達課程編制委員會暨直播委員會精心打造的&#xff0c;能夠“讓您深入理解軟件計算、設置等原理,遇到問題有處理思路,以常見問題為導向&#xff0c;重點進行原因分析&#xf…

帶有Spring,Hibernate,Akka,Twitter Bootstrap,Apache Tiles和jQuery的Maven Web項目Kickstarter代碼庫...

我很高興將第二個項目上傳到GitHub&#xff0c;以幫助人們盡快開始Java Web App開發。 我正在與Apache License 2.0共享此代碼。 這是相同的網址&#xff1a; https://github.com/ykameshrao/spring-hibernate-springdata-springmvc-maven-project-framework 該項目包括以下部…

git項目添加.gitigore文件

以前一直沒有注意這個文件&#xff0c;最近讀到了黃勇的《架構探險》&#xff0c;覺得這個文件還是很有用的。 .gitigore文件可以自己配置。 我使用的是書中所用的配置&#xff0c;簡潔明了。 # Maven # target/#log# logs/# IDEA # .idea/ *.iml# Eclipse # .settings/ .metad…

463. 島嶼的周長

給定一個 row x col 的二維網格地圖 grid &#xff0c;其中&#xff1a;grid[i][j] 1 表示陸地&#xff0c; grid[i][j] 0 表示水域。 網格中的格子 水平和垂直 方向相連&#xff08;對角線方向不相連&#xff09;。整個網格被水完全包圍&#xff0c;但其中恰好有一個島嶼&a…

C++服務器設計(七):聊天系統服務端實現

在之前的章節中&#xff0c;我們對服務端系統的設計實現原理進行了剖析&#xff0c;在這一章中&#xff0c;我們將對服務端框架進行實際運用&#xff0c;實現一款運行于內網環境的聊天系統。該聊天系統由客戶端與服務器兩部分組成&#xff0c;同時服務端通過數據庫維護用戶的賬…

高校實驗室管理系統_史上最全面的實驗室信息管理系統(LIMS)全解

1. LIMS的基本概念和發展狀況1.1 概括LIMS實驗室管理系統是為實驗、檢測等業務板塊提供流程化、模塊化、標準化操作管理系統&#xff0c;打造基于行業法規的實驗室全流程質量控制管理系統&#xff0c;實現實驗室“人、機、料、法、環”關鍵環節管理。1.2 發展狀況隨著科研規范化…

ORM問題

在過去的幾年中&#xff0c;像Hibernate這樣的對象關系映射工具已經幫助開發人員在處理關系數據庫方面取得了巨大的生產力增長。 ORM使開發人員可以將精力集中在應用程序邏輯上&#xff0c;并避免為諸如插入或查詢之類的簡單任務編寫大量樣板SQL。 但是&#xff0c;充分證明的對…