LightOJ 1213 Fantasy of a Summation
来源:互联网 发布:打鱼软件开发 编辑:程序博客网 时间:2024/06/01 09:17
题意:
给出一段代码看懂简化下,Lightoj上有好多这种数论题了,这题就是说有k层循环每层遍历n个数字,最后把k层遍历到的数字全部加和取模。
思路:
水题,稍微推下公式就有res=n^k*k/n*sum%mod;就是一共有n^k种组合,每种组合k个数字,平均分给n个数字,之后快速幂解决。
代码:
long long n,m,mod,sum,t;long long power(long long x,long long k,long long mod){long long ans = 1;while(k) {if(k & 1) ans=ans*x%mod;x=x*x%mod;k >>= 1;}return ans;}int main(){ int i,j,k,kk,x,y,z; scanf("%d",&k); kk=0; while(k--) { scanf("%lld%lld%lld",&n,&m,&mod); sum=0; for(i=0;i<n;i++){scanf("%lld",&t);sum+=t;} printf("Case %d: %lld\n",++kk,power(n,m-1,mod)*m%mod*sum%mod); } return 0;}
0 0
- lightOJ 1213 Fantasy of a Summation
- LightOJ 1213 Fantasy of a Summation
- LightOJ 1213 Fantasy of a Summation
- LightOJ 1213 - Fantasy of a Summation (排列组合+快速幂)
- lightoj 1213 - Fantasy of a Summation 【数学计数】
- LightOJ 1213 Fantasy of a Summation(快速幂)
- Fantasy of a Summation
- Fantasy of a Summation
- LightOj 1220 Fantasy of a Summation(快速幂)
- 【Light】[1213]Fantasy of a Summation
- lightoj1213 - Fantasy of a Summation
- LightOJ1213 Fantasy of a Summation
- light oj 1213 - Fantasy of a Summation (数学计数)
- light oj 1220 Fantasy of a Summation
- Light OJ 1213 Fantasy of a Summation (快速幂+规律)
- Fantasy of a Summation(找规律,水)
- ACM_1007_Numerical Summation of a Series
- Numerical Summation of a Series
- 安卓控件使用系列4:TextView实现跑马灯效果
- 后缀数组模板
- 进阶之路___(弱校联萌好题集合)
- Android通过点击按钮改变Activity的背景颜色_个人笔记
- hdu 1009 FatMouse' Trade
- LightOJ 1213 Fantasy of a Summation
- 迷宫求解(使用队列
- linux个人学习笔记---ubuntu14.10删除播放器历史记录命令
- ios浅谈关于nil和 NIL区别及相关问题
- 原码, 反码, 补码 详解
- 【凸包构造】poj 1113 Wall
- 用一张图说明负载均衡和服务器集群
- HDU5482给大小为k的字符集,求长度为n且有m个非空字串的串数目,构造
- html5 storage