Nyoj James's troubles: 181

Source: Internet
Author: User
James's hard work time limit: 3000 MS | memory limit: 65535 KB difficulty: 2
Description

In class, James learned to use a computer to find the N factorial. When he got home, he showed off to his sister. In order not to let my brother be too complacent, my sister gave James a question: "Since you will ask for the n factorial, you can help me calculate 1! + 2! -3! + 4! -5! + ...... N !". Now James is in trouble.

Are you smart enough to help him?
Input
In the first line, enter an integer T (0 <t <= 20), which indicates that there are T groups of test data.
There are t rows, and each row enters a positive integer N (0 <n <= 20 ).
Output
Each group of test data occupies one row. Output 1! + 2! -3! + ..... N! .
Sample Input
224
Sample output
321

 

# Include <stdio. h> # include <stdlib. h> int main () {int n, m, I, j; long sum, JI; scanf ("% d", & N); While (n --) {scanf ("% d", & M); sum = 1; for (I = 2; I <= m; I ++) {Ji = 1; for (j = 1; j <= I; j ++) {Ji * = J;} if (I> 1) if (I % 2 = 0) sum + = Ji; elsesum-= Ji;} printf ("% LLD \ n", sum);} return 0 ;}

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.