- 题目描写叙述:
-
输入n,
求y1=1!+3!+...m!(m是小于等于n的最大奇数)
y2=2!+4!+...p!(p是小于等于n的最大偶数)。
- 输入:
-
每组输入包含1个整数:n
- 输出:
-
可能有多组測试数据。对于每组数据,
输出题目要求的y1和y2
- 例子输入:
-
4
- 例子输出:
-
7 26
package oj1179; import java.math.BigInteger; import java.util.Scanner; public class oj1179{ public static void main(String args[]){ Scanner in=new Scanner(System.in); int i,k; int n; BigInteger y1,y2,tempY1,tempY2; while(in.hasNext()){ n=in.nextInt(); if(0==n){ System.out.println(1+" "+1); continue; } y1=new BigInteger("0"); y2=new BigInteger("0"); tempY1=new BigInteger("1"); tempY2=new BigInteger("1"); for(i=1;i<=n;i++){ if(i%2==0){ for(k=1;k<=i;k++){ tempY1=tempY1.multiply(BigInteger.valueOf(k)); }//for k y1=y1.add(tempY1); tempY1=BigInteger.valueOf(1); //System.out.println(y1+" "+i); }//if else{ for(k=1;k<=i;k++){ tempY2=tempY2.multiply(BigInteger.valueOf(k)); } y2=y2.add(tempY2); tempY2=BigInteger.valueOf(1); //System.out.println(y2+" "+i); } }//for i System.out.println(y2+" "+y1); }//while } } <div class="line number42 index41 alt1"><code class="java preprocessor">/**************************************************************</code></div><div class="line number43 index42 alt2"><code class="java spaces"> </code><code class="java preprocessor">Problem: 1179</code></div><div class="line number44 index43 alt1"><code class="java spaces"> </code><code class="java preprocessor">User: Carvin</code></div><div class="line number45 index44 alt2"><code class="java spaces"> </code><code class="java preprocessor">Language: Java</code></div><div class="line number46 index45 alt1"><code class="java spaces"> </code><code class="java preprocessor">Result: Accepted</code></div><div class="line number47 index46 alt2"><code class="java spaces"> </code><code class="java preprocessor">Time:100 ms</code></div><div class="line number48 index47 alt1"><code class="java spaces"> </code><code class="java preprocessor">Memory:15700 kb</code></div><div class="line number49 index48 alt2"><code class="java preprocessor">****************************************************************/</code></div>