1. 程式人生 > >ACM-ICPC 2018 焦作賽區網路預賽 G Give Candies (尤拉降冪)

ACM-ICPC 2018 焦作賽區網路預賽 G Give Candies (尤拉降冪)

There are N children in kindergarten. Miss Li bought them N 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), 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 T, the number of test case.

The next T 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

輸出2的n-1次方,由於n的範圍太大,所以用到尤拉降冪,降冪時直接採用同餘模定理即可。
程式碼實現:

/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
char s[N];

ll solve(ll m)
{
	ll len = strlen(s),ans = 0;
	for (ll i = 0;i < len;i++)
		ans = (ans*10+s[i]-'0')%m;
	return ans;
}

int main()
{
	int t,i,j;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%s",s);
		ll k = solve(mod-1);
		ll ans = fpow(2,k-1);
		printf("%lld\n",ans);
	}
}