ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies (欧拉降幂)

版权声明:欢迎转载,请注明此博客地址。 https://blog.csdn.net/Ever_glow/article/details/82717139

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);
	}
}

猜你喜欢

转载自blog.csdn.net/Ever_glow/article/details/82717139
今日推荐