ACM-ICPC 2018 焦作赛区网络预赛 -I Give Candies(扩展欧拉定理+大数取模)

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 \le T \le 1001≤T≤100

1 \le N \le 10^{100000}1≤N≤10100000

Output

For each test case output the number of possible results (mod 1000000007).

样例输入复制

1
4

样例输出复制

8

题目来源

ACM-ICPC 2018 焦作赛区网络预赛


题解:

由题目可推出:ans=2^{n-1} mod 1000000007 ;毫无疑问只是一道大数取模的题

由欧拉公式可知    gcd(2,1000000007)=1;所以:ans=2^n %1000000007  % 1000000007=2^(n % φ(1000000007));

φ(1000000007)=1000000006;  

由余数定理可知:(a+b)%d=(a%d+b%d)%d    a*b%d=(a%d*b%d)%d;

所以n可以用字符串存取然后每次乘10相加  取模就好。


#include<cstring>
#include<cstdio>
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<functional>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define dec(a,b,c) for(int a=b;a>c;a--)
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define ps(x) push(x)
#define MAX_N 100000+5
#define MAX_M 100
typedef long long ll;
typedef unsigned long long ull;
typedef priority_queue<ll,vector<ll>,greater<ll> >pqg;
const ll maxn=1e3;
const ll inf=1e7;
ll mod=1e9+7;
ll q_pown(ll a,ll b)
{
    ll ans=1;
    while(b>0)
    {
        if(b&1)
        {
            ans*=a;
            ans%=mod;
        }
        a=a*a;
        a%=mod;
       b>>=1;
    }
    return ans;

}
int main()
{
#ifndef ONLINE_JUDGE
    // freopen("data.txt","r",stdin);
#endif    int t;
    scanf("%d",&t);
    while(t--)
    {
        string s;
        cin>>s;
        ll n=0;
        mod--;
        for(int i=0;i<s.size();i++)
        {
            n=n*10+s[i]-'0';
            if(n>=mod)n%=mod;
        }
       if(n<0)
            n+=mod;
        mod++;
        printf("%lld\n",q_pown(2,n-1));
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值