码迷,mamicode.com
首页 > 其他好文 > 详细

ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies

时间:2018-09-15 20:02:19      阅读:403      评论:0      收藏:0      [点我收藏+]

标签:RoCE   nbsp   http   cli   The   children   can   tar   费马小定理   

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 NN.

1 \le T \le 1001T100

1 \le N \le 10^{100000}1N10100000

Output

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

样例输入

1
4

样例输出

8

题目来源

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

题解:费马小定理:a^n%p=a^(n%(p-1))%p;只要求n%(p-1)然后,快速幂求a^()即可:

参考代码为:

#include<stdio.h>
#define MOD 1000000007
char st[100001];
int T;
long long sum;
int main()
{
	scanf("%d",&T);
    while(T--)
	{
		scanf("%s",st);
        int i=0,j;
        sum=0;
        while(st[i]!=‘\0‘)
		{
            sum=sum*10;
            sum+=(st[i]-‘0‘);
            i++;
            sum=sum%(MOD-1);
        }
        sum=sum-1;
        long long temp=2,ret=1;
        while(sum)
		{
            if(sum&1) ret=ret*temp%MOD;
            temp=temp*temp%MOD;
            sum>>=1;
        }
        printf("%lld\n",ret);
    }
    return 0;
}

  

ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies

标签:RoCE   nbsp   http   cli   The   children   can   tar   费马小定理   

原文地址:https://www.cnblogs.com/songorz/p/9651898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!