A 201,500-degree star Qualifying tournament for the big move

Source: Internet
Author: User

Big move
Time limit:2000/1000 MS (java/others)
Memory limit:65536/65536 K (java/others)
Problem Description

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) n (1 \leq n \leq 1) n (1≤n≤1000000).
Output

For each set of data, output one line of case #i: Then output the result, modulo 100000000710000000071000000007.
Sample Input

2
1
3

Sample Output

Case #1:
1
Case #2:
4

This problem, is a recursive problem, that is, this can only be met in two cases, one is self-
The other is to exchange each other.
So, recursion, for the first I, you can choose to self-intersection (that is, themselves and their own), then there are a[i-1] ways
For mutual exchange, there are a[i-2] methods

Importjava.util.*;ImportJava.math.BigInteger; Public  class Main{     Public Static void Main(string[] args) {intN,t; Scanner cin=NewScanner (system.in); T=cin.nextint ();intcoun=1;Final LongMod=1000000007;Final intmaxn=1000005;Long[] A=New Long[MAXN]; a[0]=a[1]=(Long)1; for(intI=2; i<=1000000; ++i) {a[i]=a[i-1]+ ((I-1) *a[i-2])%mod;        A[i]%=mod; } while(t-->0) {n=cin.nextint (); System.out.print ("Case #"+coun+": \ r \ n"+a[n]+"\ r \ n");        ++coun;    } cin.close (); }}

Big move 201,500-degree star Qualifying tournament

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.