codeforces 893E(组合数学&组合数取mod)
来源:互联网 发布:织梦wap模板 编辑:程序博客网 时间:2024/06/10 12:38
题目链接:http://codeforces.com/problemset/problem/893/
先质因子分解此题可以转化为n个数字放入y个空格中所以用插空法C(y-1+t,y-1)计算出情况
在这里数字还可以是负数所以在原来的基础上将偶数个数字变成负数C(y,0)+C(y,2)+C(y,4)+...
化简为2^(y-1)
推倒:
(1+x)^n=C(n,0)+C(n,1)*x+...+C(n,n)*x^n
取x=-1得到C(n,0)-C(n,1)+...+(-1)^n*C(n,n)=2^n
取x=1得到C(n,0)+C(n,1)+...+(-1)^n*C(n,n)=0
推出 C(n,0)+C(n,2)+...=2^n-1
计算2^n-1的时候用快速幂即可
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <vector>using namespace std;typedef long long int LL;const int maxn=2e6;const int mod=(1e9)+7;LL fac[maxn]={};LL num_pow(LL a,LL k){ LL res=1,tem=a; for(;k;k>>=1){ if(k&1) res=(res*tem)%mod; tem=(tem*tem)%mod; } return res;}LL C(LL n,LL m){ return (fac[n]*num_pow(fac[m],mod-2))%mod*num_pow(fac[n-m],mod-2)%mod; //阶层取mod}LL Lucas(LL n,LL m ) { //不要用Lucas会T的(在这里写出来是为了以后方便用) if(m==0) return 1; else return (C(n%mod,m%mod)*Lucas(n/mod,m/mod))%mod;}int main(){ LL q,n,k; scanf("%lld",&q); fac[0]=1; for(int i=1;i<2e6;i++) fac[i]=fac[i-1]*i%mod; while(q--){ scanf("%lld%lld",&n,&k); LL ans=num_pow(2,k-1); for(LL i=2;i*i<=n;i++)if(n%i==0){ int t=0; while(n%i==0){ t++; n/=i; } ans=ans*C(t+k-1,k-1)%mod; } if(n>1) ans=(ans*k)%mod; printf("%lld\n",ans); } return 0;}
阅读全文
0 0
- codeforces 893E(组合数学&组合数取mod)
- codeforces 893E Counting Arrays (组合数学)
- Codeforces E. Qwerty78 Trip 【组合数学】
- CodeForces 51 E.Pentagon(组合数学)
- 错排公式 + 组合数学取mod板子
- CodeForces 520E. Pluses everywhere 字符串,组合数学
- Codeforces 660E Different Subsets For All Tuples【组合数学】
- Codeforces 689E Mike and Geometry Problem(组合数学)
- Codeforces 560E Gerald and Giant Chess 组合数学+DP
- CodeForces 15 E.Triangles(组合数学+dp)
- CodeForces 40 E.Number Table(组合数学)
- 【组合数学思维】CodeForces
- 组合数学-catalan数
- 组合数学:贝尔数
- Stirling数-组合数学
- 组合数学-色数
- codeforces 451E. Devu and Flowers 组合数+容斥
- poj 3088 组合数学 斯特林数+组合数
- node.js文件操作
- 2K+1找不同异或算法
- android
- windows服务开启应用程序的常见问题及解决办法
- 云和恩墨打造业内领先数据库一体机
- codeforces 893E(组合数学&组合数取mod)
- webservice学习及使用笔记
- Eclipse 编译Android Apk常见问题总结
- 基于ajax原生/jquery的上传文件
- numpy中的易混淆点
- Markdown简明语法
- 课程设计校园导游
- mac登陆服务器登陆不上
- UML 5分钟读懂UML类图