设计思想
多次按相同的累乘规则进行累乘,多次累乘可以用循环结构实现。
典型例题
一、国王奖赏问题
国际象棋有64格,国王奖赏给大臣一些麦子,按第一个格子放1粒,第二格放2粒,第三格放4粒,以后每个格子放前一个格子的两倍。问一共有多少麦子。
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
BigInteger count = king();
System.out.println(count);
}
private static BigInteger king() {
BigInteger num = BigInteger.ONE, count = BigInteger.ONE;
for (int i = 1; i <= 64; i++) {
count = count.add(num);
num = num.