Factorial sum input n, calculate s=1! +2! +3! + ... +n! The last 6 bits (excluding the leading 0). N≤10 6, n! Represents the product of the first n positive integers.

Source: Internet
Author: User

The sum of factorial
Enter N, calculate s=1! +2! +3! + ... +n! The last 6 bits (excluding the leading 0). N≤10 6, n! Said
The product of the first n positive integers.
Sample input:
10
Sample output:

Package Demo;import Java.util.scanner;public class Demo02 {public static void main (string[] args) {Scanner in=new Scanner ( system.in); int n=in.nextint (); Long sum=0;for (int i = 1; I <=n; i++) {sum=sum+jie2 (i);} String str=long.tostring (sum); Str=str.substring (Str.length () -6,str.length ()); Sum=integer.parseint (str); SYSTEM.OUT.PRINTLN (sum);} public static int jie (int num) {//if (num==1)//return  1;//else//return Jie (num-1) *num;//}public static Long Jie2 ( int num2) {long sum=1;for (int i = 1; I <=num2; i++) {sum=sum*i; String str=long.tostring (sum), if (Str.length () >6) {str=str.substring (Str.length () -7,str.length ()), sum= Integer.parseint (str); if (sum==0) {return sum=0;}}} return sum;}}

  


37913

Factorial sum input n, calculate s=1! +2! +3! + ... +n! The last 6 bits (excluding the leading 0). N≤10 6, n! Represents the product of the first n positive integers.

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.