input

T           <=10

n k            n<=1000         k<=10^18

a1,a2,...an                |ai|<=10^18

output

(a1^k+a2^k+...+an^k)%10^10+7

Sample Input

2

3 1
1 2 3
3 10
1 2 3

Sample Output

6 60074

做法:快速幂+__int128,需注意ai可能是负数,模的是10^10+9,超int了

模乘法:对一个数可以拆分为N=(P*(N/P)+(N%P))

 #include <bits/stdc++.h>
#define MAX 100000
#define LL long long
//#define __int128 long long
#define mod 10000000007LL
using namespace std;
int cas=,T;
template <class T>
bool scanff(T &ret)
{ //Faster Input
char c; int sgn; T bit=0.1;
if(c=getchar(),c==EOF) return ;
while(c!='-'&&c!='.'&&(c<''||c>'')) c=getchar();
sgn=(c=='-')?-:;
ret=(c=='-')?:(c-'');
while(c=getchar(),c>=''&&c<='') ret=ret*+(c-'');
if(c==' '||c=='\n'){ ret*=sgn; return ; }
while(c=getchar(),c>=''&&c<='') ret+=(c-'')*bit,bit/=;
ret*=sgn;
return ;
}
template <class T>
void printff(T ret)
{ //Faster Output
char s[];
if(ret<) { printf("-");ret=-ret; }
int len=;
while(ret)
{
s[++len]=ret%+'';
ret/=;
}
if(!len) s[++len]='';
while(len)
{
printf("%c",s[len]);
len--;
}
}
LL qmod( __int128 a, LL n)
{
__int128 res=;
LL flag=;
if(a<) { flag=(n&?-:);a=-a; }
a%=mod;
while(n)
{
if(n&) res=res*a%mod;
a=a*a%mod;
n>>=;
}
return (LL)res*flag;
}
int main()
{
//freopen("1.in","w",stdout);
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
scanf("%d",&T);
while(T--)
{
int n;
LL k,a,res=;
scanf("%d%lld",&n,&k);
for(int i=;i<n;i++)
{
scanf("%lld",&a);
res=(res+qmod(a,k))%mod;
}
printff((res+mod)%mod);
printf("\n");
}
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return ;
}

ACdream 1007的更多相关文章

  1. ACdream 1007 (快速幂)

    题目链接 a + b Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Problem D ...

  2. ACdream 1007 a+b 快速幂 java秒啊,快速幂 避免 负数移位出错

    a + b ( sigma  (ai^x)  )  %  mod 1 import java.util.*; 2 import java.math.*; 3 import java.io.*; 4 p ...

  3. Acdream a + b

    http://acdream.info/problem?pid=1007 两个 long long 相乘会超long long #include <cstdio> #include < ...

  4. SCNU 2015ACM新生赛初赛【1007. ZLM的扑克牌】解题报告

            题目链接详见SCNU 2015新生网络赛 1007. ZLM的扑克牌 .         其实我在想这题的时候,还想过要不要设置求最小的排列,并且对于回文数字的话,可以把扑克牌折起来( ...

  5. PKU 1007

    题名:DNA排序 题意:给定字符串长度.个数,计算每个字符串的逆序数,然后从大到小排列,有兴趣的可以去看下原题. 计算字符串逆序数,然后排序,这里使用了快速排序算法,string释放的时候竟然有问题, ...

  6. sicily 1007. To and Fro 2016 11 02

    // Problem#: 1007// Submission#: 4893204// The source code is licensed under Creative Commons Attrib ...

  7. 【HDU 1007】Quoit Design

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 最近欧式距离模板题. 用分治大法(分治的函数名用cdq纯属个人习惯_(:з」∠)_) 一开始狂M. 后来判 ...

  8. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

  9. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

随机推荐

  1. WCF服务承载

    WCF服务承载(笔记)   自托管(也做自承载) 承载 WCF 服务最灵活.最便捷的方法就是进行自承载.要能够自承载服务,必须满足两个条件.第一,需要 WCF 运行时:第二,需要可以承载 Servic ...

  2. Qt在表格中加入控件

    任务:使用QTableWidget动态生成表格,在每行的某两列中加入QComboBox下拉框控件和QPushButton按钮控件 有添加,删除,编辑功能,每行的按钮可以浏览文件夹并选择文件 1.新建一 ...

  3. [置顶] MyElipse9.0 M1安装svn(测试100%通过)

    为什么标题要写100%通过呢?原因是以前的方法(直接复制到plugin里(MyEclipse 6.0可以,我试过),link安装)都不好用了,9.0M1不吃这一套,所以告诉大家这么做一定能够装上!! ...

  4. [转] 数据库加锁 sql加锁的

    [导读: 各种大型数据库所采用的锁的基本理论是一致的,但在具体实现上各有差别.SQL Server更强调由系统来管理锁.在用户有SQL请求时,系统分析请求,自动在满足锁定条件和系统性能之间为数据库加上 ...

  5. 浅谈 Linux

          1969年,美国贝尔实验室的肯-汤普森在DEC PDP-7机器上开发出了UNIX系统.      1971年,肯-汤普森的同事丹尼斯-里奇发明了C语言:1973年,UNIX系统的绝大部分源 ...

  6. cocoaPods第三方库使用详解

    终端上安装了cocoapods后,打开终端输入下面命令: cd /Users/Sivek_lin/Desktop/AFNTest/AFNTest touch podfile pod search af ...

  7. TCP/IP协议中backlog参数

    TCP建立连接是要进行三次握手,但是否完成三次握手后,服务器就处理(accept)呢? backlog其实是一个连接队列,在Linux内核2.2之前,backlog大小包括半连接状态和全连接状态两种队 ...

  8. 实现自己的JDBC框架

    使用JDBC操作数据库时,dao层的增删改查有很多重复的代码,比如下面的 public int getTotal() { Connection conn = null;//通用代码 PreparedS ...

  9. winform自动更新并实现文件的批量异步下载

    public partial class update : Form    {        private WebClient client;        int downfilenum = 0; ...

  10. UIColor,CGColor,CIColor三者间的区别和联系

    一.UIColor UIColor是UIKit中存储颜色信息的一个重要的类,一个UIColor对象包含了颜色和透明度的值,它的颜色空间已经针对IOS进行了优化.UIColor包含了一些类方法用于创建一 ...