标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4548 | Accepted: 1731 |
Description
Input
Output
Sample Input
2 3
Sample Output
1 1
Source
import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { final int maxn = 1010; BigInteger fa[] = new BigInteger[maxn]; BigInteger fb[] = new BigInteger[maxn]; BigInteger TWO = BigInteger.valueOf(2); fa[0] = fb[0] = BigInteger.ZERO; for (int i = 1; i < maxn; i ++) { fa[i] = fa[i-1].add(fb[i-1]); fb[i] = fa[i-1].add(fb[i-1]).add(BigInteger.valueOf(i).mod(TWO)); } int n; Scanner cin = new Scanner(System.in); while (cin.hasNext()) { n = cin.nextInt(); System.out.println(fb[n-1]); } } }
Python
import sys fa = [0] * 1010 fb = [0] * 1010 fa[0] = 0; fb[0] = 0; for i in range(1, 1010): fa[i] = fa[i-1] + fb[i-1] fb[i] = fa[i-1] + fb[i-1] + i % 2 for line in sys.stdin: n = int(line) print(fb[n-1])
标签:
原文地址:http://www.cnblogs.com/LinKArftc/p/4969430.html