题目1179:阶乘
2015-05-01 13:46
309 查看
题目描述:
输入n,
求y1=1!+3!+...m!(m是小于等于n的最大奇数)
y2=2!+4!+...p!(p是小于等于n的最大偶数)。
输入:
每组输入包括1个整数:n
输出:
可能有多组测试数据,对于每组数据,
输出题目要求的y1和y2
样例输入:
样例输出:
输入n,
求y1=1!+3!+...m!(m是小于等于n的最大奇数)
y2=2!+4!+...p!(p是小于等于n的最大偶数)。
输入:
每组输入包括1个整数:n
输出:
可能有多组测试数据,对于每组数据,
输出题目要求的y1和y2
样例输入:
4
样例输出:
7 26
import java.math.BigInteger; import java.util.Scanner; public class Main{ public static void main(String[]args){ Scanner in=new Scanner(System.in); long[]re=new long[10001]; for(int i=1;i<re.length;i++) re[i]=1; for(int i=1;i<re.length;i++){ for(int j=1;j<=i;j++){ re[i]*=j; } } while(in.hasNext()){ int n=in.nextInt(); BigInteger y1=new BigInteger("0"); BigInteger y2=new BigInteger("0"); for(int i=1;i<=n;i++){ BigInteger an=JC(i); if(i%2!=0){ y1=y1.add(an); } else{ y2=y2.add(an); } } System.out.println(y1+" "+y2); } } public static BigInteger JC(int n){ BigInteger an=new BigInteger("1"); for(int i=1;i<=n;i++){ BigInteger tem=new BigInteger(String.valueOf(i)); an=an.multiply(tem); } return an; } } /************************************************************** Problem: 1179 User: 0000H Language: Java Result: Accepted Time:290 ms Memory:17448 kb ****************************************************************/
相关文章推荐
- 题目1179:阶乘
- 九度题目1179:阶乘
- 九度 题目1179:阶乘
- 题目1179:阶乘
- 题目1179:阶乘
- 题目1179:阶乘
- 题目1179:阶乘
- 九度OJ题目1179:阶乘
- 题目1179:阶乘
- 九度oj 题目1179:阶乘
- 九度OJ 题目1179:阶乘
- 九度OJ 题目1179:阶乘
- 【九度OJ】题目1179:阶乘 解题报告
- NYOJ 题目阶乘因式分解(二)(数学)
- [Java经典题目]计算阶乘的和
- NYOJ 题目91 阶乘之和
- 题目65-另一种阶乘问题
- 2015年华为面试用C语言编写一个求大数字阶乘算法的题目
- 题目1066:字符串排序 题目1067:n的阶乘 题目1068:球的半径和体积
- 题目1072:有多少不同的面值组合? 题目1074:对称平方数 题目1075:斐波那契数列 题目1076:N的阶乘