博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lightoj1213推公式
阅读量:4691 次
发布时间:2019-06-09

本文共 955 字,大约阅读时间需要 3 分钟。

很容易推出来的公式ans=n^(k-1)*k*sum

然后快速幂就好了

#include#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define pi acos(-1.0)#define ll long long#define mod 1000000007#define ls l,m,rt<<1#define rs m+1,r,rt<<1|1#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;const double g=10.0,eps=1e-7;const int N=10000+10,maxn=500+100,inf=0x3f3f3f;ll a[N];ll quickmul(ll a,ll b,ll mo){ ll ans=1; while(b){ if(b&1)ans=(ans*a)%mo; a=(a*a)%mo; b/=2; } return ans%mo;}int main(){ ios::sync_with_stdio(false); cin.tie(0); ll t,cnt=0; cin>>t; while(t--){ ll n,k,mo,sum=0; cin>>n>>k>>mo; for(int i=0;i
>a[i]; sum=(sum+a[i])%mo; } ll ans=quickmul(n,k-1,mo); ans=(ans*k)%mo; ans=(ans*sum)%mo; cout<<"Case "<<++cnt<<": "<
<
View Code

 

转载于:https://www.cnblogs.com/acjiumeng/p/7227374.html

你可能感兴趣的文章
POJ - 3294 Life Forms
查看>>
JQuery 获取URL中传递的参数
查看>>
AWT和Swing
查看>>
每天一个linux命令(11):nl命令
查看>>
pytorch查看模型weight与grad
查看>>
Leetcode Remove Nth Node From End of List
查看>>
java中的异常
查看>>
Gym 100342J Triatrip (求三元环的数量) (bitset优化)
查看>>
html模块常用命名总结
查看>>
Linux - 修改系统的max open files、max user processes (附ulimit的使用方法)
查看>>
js判断IE浏览器及版本
查看>>
百度地图手机端单触点单击和长按事件,解决部分手机(小米手机)地图单击事件失效,多触点、拖动依然触发长按的bug...
查看>>
OpenXml开发-向文档中添加样式
查看>>
FastDFS单机搭建以及java客户端Demo
查看>>
[原创]IPV4分组的格式
查看>>
YTU 2837: 编程题B-狐狸算卦
查看>>
复杂对象ibatis插入,属性为list,怎么一次性插入
查看>>
微信公众号H5支付遇到的那些坑
查看>>
你看,那个人好像一条狗哎
查看>>
数据库游标及其优点
查看>>