hdu5047 Sawtooth 规律 + JAVA大数
Total Submission(s): 2272 Accepted Submission(s): 834
● One straight line can divide a plane into two regions.
● Two lines can divide a plane into at most four regions.
● Three lines can divide a plane into at most seven regions.
● And so on...
Now we have some figure constructed with two parallel rays in the same direction, joined by two straight segments. It looks like a character “M”. You are given N such “M”s. What is the maximum number of regions that these “M”s can divide a plane ?
Each case contains one single non-negative integer, indicating number of “M”s. (0 ≤ N ≤ 10 12)
2 1 2
Case #1: 2 Case #2: 19
f(n) = 8 * n * n - 7 * n + 1
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;public class Main {public static void main(String[] args) {Scanner in = new Scanner(new BufferedInputStream(System.in));PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));int T, kase;T = in.nextInt();kase = 0;BigInteger n, ans;while (T-- != 0) {n = in.nextBigInteger();ans = BigInteger.valueOf(8).multiply(n).multiply(n).subtract(BigInteger.valueOf(7).multiply(n)).add(BigInteger.ONE);out.printf("Case #%d: ", ++kase);out.println(ans.toString());}in.close();out.close();}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
