There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N)(1...N), and each time a child is invited, Miss Li randomly gives him some candies (at least one). The process goes on until there is no candy. Miss Li wants to know how many possible different distribution results are there.
Input
The first line contains an integer TT, the number of test case.
The next TT lines, each contains an integer N.
1≤T≤100
1≤N≤10^100000
Output
For each test case output the number of possible results (mod 1000000007).
样例输入复制
1
4
样例输出复制
8
题目来源
费马小定理 : 如果mod为质数,(a^n )%mod = a^(n%(mod-1)) %mod
潜意识觉得适合先打个表_(:з」∠)_
#include<bits/stdc++.h>
using namespace std;
int ans;
void DFS(int n)
{
if(n==0)
{
ans++;
return ;
}
for(int i=n;i>=1;i--)
{
DFS(n-i);
}
}
int main(void)
{
int n;
while(cin>>n)
{
ans=0;
DFS(n);
cout<<ans<<endl;
}
}
哈哈哈哈哈哈~ 规律出来啦ans = 2^(n-1)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll quick_pow(int a,ll n )
{
ll ret = 1;
ll temp = a;
while(n)
{
if(n&1) (ret *= temp)%=mod;
(temp *= temp)%=mod;
n>>=1;
}
return ret;
}
int main(void)
{
std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int T;cin>>T;
while(T--)
{
string s;
cin>>s;
ll n=0;
for(int i=0;i<s.length();i++)
n = (n*10+s[i]-'0') % (mod-1);
cout<<quick_pow(2,n-1)<<endl;
}
}