标签:online judge 九度 java 编程
输入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>
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:online judge 九度 java 编程
原文地址:http://blog.csdn.net/carvin_zh/article/details/47747151