Our Chef is catering for a big corporate office party and is busy preparing different mouth watering dishes. The host has insisted that he serves his delicious cupcakes for dessert.
On the day of the party, the Chef was over-seeing all the food arrangements as well, ensuring that every item was in its designated position. The host was satisfied with everything except the cupcakes. He noticed they were arranged neatly in the shape of a rectangle. He asks the Chef to make it as square-like as possible.
The Chef is in no mood to waste his cupcakes by transforming it into a perfect square arrangement. Instead, to fool the host, he asks you to arrange the N cupcakes as a rectangle so that the differencebetween the length and the width is minimized.
The first line of the input file contains an integer T, the number of test cases. Each of the following T lines contains a single integer N denoting the number of cupcakes.
Output T lines, each indicating the minimum possible difference between the length and the width in a rectangular arrangement of the cupcakes.
1 ≤ T ≤ 100
1 ≤ N ≤ 108
一題簡單的因子分解題目。
思路有兩個:
1 從根号2開始分解,第一個能夠分解的兩個因子就是答案
2 利用素數,找出全部的因子,然後求解
這裡使用第二中方法。這個比較有挑戰性。
本文轉自mfrbuaa部落格園部落格,原文連結:http://www.cnblogs.com/mfrbuaa/p/5370121.html,如需轉載請自行聯系原作者