zoukankan      html  css  js  c++  java
  • ACM-ICPC 2018 焦作赛区网络预赛 G题 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 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^()即可:

    参考代码为:

     1 #include<stdio.h>
     2 #define MOD 1000000007
     3 char st[100001];
     4 int T;
     5 long long sum;
     6 int main()
     7 {
     8     scanf("%d",&T);
     9     while(T--)
    10     {
    11         scanf("%s",st);
    12         int i=0,j;
    13         sum=0;
    14         while(st[i]!='')
    15         {
    16             sum=sum*10;
    17             sum+=(st[i]-'0');
    18             i++;
    19             sum=sum%(MOD-1);
    20         }
    21         sum=sum-1;
    22         long long temp=2,ret=1;
    23         while(sum)
    24         {
    25             if(sum&1) ret=ret*temp%MOD;
    26             temp=temp*temp%MOD;
    27             sum>>=1;
    28         }
    29         printf("%lld
    ",ret);
    30     }
    31     return 0;
    32 }
    33   
    View Code
  • 相关阅读:
    Python和C#基本算法实现对比
    数据库并发
    NetCore 启动地址配置详解
    SkyWalking Liunx 环境搭建&NetCore接入
    Autofac踩坑经历
    centos 7 安装elasticsearch
    centos 7 java1.8安装
    AppDomin学习与分享
    .Net 程序代码混淆加密工具 ILProtector
    c# 重新认识 Double 浮点型
  • 原文地址:https://www.cnblogs.com/csushl/p/9651898.html
Copyright © 2011-2022 走看看