"201,500-degree star" big move

Source: Internet
Author: User

Big Move Topic

Recently, b factory organized a big move, everyone to follow the instructions to change to the designated seat. The indication is that the person sitting on position III will be moved to the position jjj. Now B Factory has nnn individual, one to nnn position. After the move is also one by one corresponding, change only the rank.

After the first move, the degree of bear due to negligence, but also asked you to follow the original instructions for a move. So, the wit of it thought: again according to the instructions to move home once again can restore the first time the appearance of the move. As a result, plant B has carried out an unprecedented three consecutive moves.

While we all know that the "wit" of a bear is often worrying, it is inconceivable that this is a real thing. The result of the third move is exactly the same as the result of the first time.

So, how many kinds of instructions are going to make this happen? If at least one of the two instructions has a different target location, the two instructions are considered to be not the same.

Input
The first line is an integer TTT, which represents the T-group data.
Each set of data contains an integer n (1 ≤ N ≤ 1000000).

Output
For each set of data, output one line of case #i: Then output the result, modulo 1000000007.

Exercises

Initially wanted to use combinatorial mathematics to write, found that the formula introduced and there is no good way to achieve ...
Later, I began to want to push forward, found that recursion is still very good writing.
Set F n Consider the last person for the solution of n person, he either himself becomes a team, or is paired with one of the previous n-1 individuals.
So there are: F n = F n? 1 +(N?1) F n? 2 。

Code
#include <iostream>#include <cstdio>#include <cstring>#define MOD 1000000007using namespace STD;Long Longa[1000005];intN,t;intMain () {a[1]=1; a[2]=2; for(intI=3; i<=1000000; i++) a[i]= (a[i-1]+ (a[i-2]* (I-1))%mod)%mod;scanf("%d", &t);intCase=1; while(t--) {scanf("%d", &n);printf("Case #%d:\n%i64d\n", Case++,a[n]); }return 0;}

"201,500-degree star" big move

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.