Topic 1179: Factorial

Source: Internet
Author: User

Title Description:

Enter N,
Beg y1=1!+3!+...m! (M is the largest odd number less than or equal to N)
y2=2!+4!+...p! (P is the largest even number less than or equal to N).

Input:

Each set of inputs consists of 1 integers: n

Output:

There may be multiple sets of test data, for each set of data,
Output the Y1 and Y2 of the topic requirements

Sample input:
4
Sample output:
7 26
Source:

2000 Huazhong University of Science and technology computer research life test real problem



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 Ky1=y1.add (tempY1); tempy1=biginteger.valueof (1);//system.out.println (y1+ "" +i);} Ifelse{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 ISystem.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" >  &nbsP; </code><code class= "Java preprocessor" >memory:15700 kb</code></div><div class= " Line number49 index48 alt2 "><code class=" java preprocessor ">********************************************** /</code></div>


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Topic 1179: Factorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.