Give Candies

题意:有n颗糖,有n个人,按顺序出列,每次随机给那个人一些糖(至少一颗),分完为止,求有多少方案

思路:规律是2^(n−1) 根据费马小定理  a^(p−1)=1(mod p), 那么先n%p,然后使用快速幂

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5+7,mod=1e9+7;
char str[maxn];
/*
LL quick_mul(LL a,LL b)
{LL ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;}return ans;
}
*/
LL quick_pow(LL a,LL b)
{LL ret=1;while(b){if(b&1)//ret=quick_mul(ret,a);ret=(ret*a)%mod;//a=quick_mul(a,a);a=(a*a)%mod;b>>=1;}return ret;
}
int main()
{int T;scanf("%d",&T);while(T--){scanf("%s",str);int len=strlen(str);LL num=0;for(int i=0;i<len;i++){num=(num*10+str[i]-'0')%(mod-1);}printf("%lld\n",quick_pow(2,num-1));}
}

ACM-ICPC 2018 焦作赛区网络预赛相关推荐

  1. ICPC 2018 焦作赛区网络预赛G Give Candies 组合数学隔板法+欧拉降幂

    G Give Candies 计蒜客 G Give Candies 题意 n n n个糖果, n n n个人从 1 1 1~ n n n编号,每次给一个人发糖可以发任意数量但不能小于 1 1 1,直到 ...

  2. ACM-ICPC 2018 焦作赛区网络预赛 J(二分+JAVA高精)

    传送门 题面: 65536K Jessie and Justin want to participate in e-sports. E-sports contain many games, but t ...

  3. ACM-ICPC 2018 焦作赛区网络预赛 H题 String and Times(SAM)

    Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring won ...

  4. L. Poor God Water(ACM-ICPC 2018 焦作赛区网络预赛,ac自动机+矩阵快速幂 或 BM线性递推)

    描述 God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells hi ...

  5. ACM-ICPC 2018 焦作赛区网络预赛 A. Magic Mirror (水)| B . Mathematical Curse(dp)

    A 题目: Jessie has a magic mirror. Every morning she will ask the mirror: 'Mirror mirror tell me, who ...

  6. ACM-ICPC 2018 焦作赛区网络预赛(A B E F G H I K L)

    ACM-ICPC 2018 焦作赛区网络预赛(A B E F G H I K L) 发了博客一万年之后才发现H1写错了(tao A. Magic Mirror 题目链接 题面: Jessie has ...

  7. ACM-ICPC 2018 焦作赛区网络预赛 L Poor God Water(BM算法)

    题目链接:https://nanti.jisuanke.com/t/31721 题目大意:三种食物,n小时,连续三小时不能吃一样的东西,中间吃巧克力时连续三个小时吃的东西不能完全不同,如果中间吃鱼或者 ...

  8. ACM-ICPC 2018 焦作赛区网络预赛 L. Poor God Water

    #题解 大佬的递推式子..本弱鸡具体怎么得到的也不是很清楚 f(1)=3,f(2)=9,f(3)=20,f(4)=46,f(5)=106 f(n)=2f(n-1)-f(n-2)+3f(n-3)+2*f ...

  9. ACM-ICPC 2018 焦作赛区网络预赛A. Magic Mirror(签到题)

    Jessie has a magic mirror. Every morning she will ask the mirror: 'Mirror mirror tell me, who is the ...

最新文章

  1. 用AI为美国政府“助纣为虐”,微软员工怒了
  2. 【官方权威教程】 PyTorch 深度学习, 学习PyTorch的必备宝典!
  3. Cell子刊:大鱼大肉吃三天,体重未动大脑先变,不仅发胖还会发炎
  4. maven中pom.xml中依赖包代码的查询地址
  5. Oracle Open World 2012信息汇总贴
  6. 盐城工学院计算机考研高吗,信息学院计算机班计玮考取中南大学研究生
  7. linux编译项目的命令,Linux用make指令编译进度条程序
  8. linux各机器之间配置无密码访问
  9. 找出数组中第i小元素(时间复杂度Θ(n)--最坏情况为线性的选择算法
  10. 2021牛客NOIP提高组第二场T2——方格计数(组合数计数)
  11. 硬件磁盘阵列还是软件磁盘阵列
  12. Hibernate 简介
  13. URAL 1664 Pipeline Transportation
  14. 调参心得:超参数优化之旅
  15. J2EE的体系架构——J2EE
  16. android8.1 BLE从设备开发MAC地址随机问题
  17. 一文读懂Nabla算子
  18. Rational Rose 2007简单介绍及详细安装步骤
  19. 2019网易游戏测试开发实习电话面试总结
  20. 戏说python模块

热门文章

  1. ios ionic3 跳转第三方地图 xcode加入白名单
  2. python-windows环境安装
  3. Codeforces div2 #499 B. Planning The Expedition 大水题
  4. 第一篇文章,,测试效果,
  5. CSS3的chapter3
  6. 让Vs2013 完美支持EF6.1 Code First with Oracle 2015年12月24日更新
  7. MySQL 同步(三)不同版本问题
  8. redis 2m数据读取_Flink读写Redis(二)读取redis数据
  9. node工程默认url_node.js处理url常用方法
  10. java内部类写法_Java学习-内部类