Codeforces Round #209 (Div. 2)C
刷了一页的WA 。。终于发现了 哪里错了 快速幂模板里一个变量t居然开得long ...
虽然代码写的丑了点 但是是对的 那个该死的long 啊..
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
using namespace std;
#define mod 1000000007
#define LL __int64
#define N 100010
LL n,x,a[N],s,b[N];
LL exp_mod(LL a,LL n,LL b)
{
long long t;
if(n==) return %b;
if(n==) return a%b;
t=exp_mod(a,n/,b);
t=t*t%b;
if((n&)==) t=t*a%b;
return t;
}
int main()
{
int i;
cin>>n>>x;
for(i = ; i <= n ; i++)
{
scanf("%I64d",&a[i]);
s = s+a[i];
b[i] = a[i];
}
for(i = ; i <= n ; i++)
{
b[i] = s-a[n-i+];
}
for(i = ; i <= n ;i++)
a[i] = b[i];
LL k = a[];
int o = ;LL ss=a[];
LL sum=;
b[]-=a[];
while()
{
if(b[o]==&&o<=n)
{
o++;
b[o]-=a[o-];
sum++;
if(o>n) break;
else
continue;
}
if(o>n) break;
if(sum%x!=) break;
while(sum%x==&&o<=n)
{
sum/=x;
ss++;
b[o]--;
if(b[o]==)
{
o++;
b[o]-=a[o-];
sum++;
break;
}
}
if(o>n) break;
}
while(sum&&sum%x==)
{
ss+=;
sum/=x;
}
printf("%I64d\n",exp_mod(x,min(s,ss),mod));
return ;
}
Codeforces Round #209 (Div. 2)C的更多相关文章
- Codeforces Round #209 (Div. 2) B. Permutation
解题思路: 如果序列a是单调递增的,则序列为1,2,..... 2n,则将给出的式子化简得Σ(a2i - a2i-1) = n 如果序列a是单调递减的,则序列为2n,.........2, 1,则将给 ...
- Codeforces Round #209 (Div. 2) A. Table
#include <iostream> #include <vector> using namespace std; int main(){ int n,m; cin > ...
- Codeforces Round #209 (Div. 2)
A: 要么是两次要么4次,判断是否在边界: #include<cstdio> using namespace std; int main() { int n,m,x; ; scanf(&q ...
- Codeforces Round #209 (Div. 2)A贪心 B思路 C思路+快速幂
A. Table time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #209 (Div. 2) D. Pair of Numbers (模拟)
D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #209 (Div. 2) C - Prime Number
传送门 题意 给出n个数及x,求 \[\frac{\sum _{i=1}^n x^{a_1+a_2+...+a_{i-1}+a_{i+1}+...a_n}}{\prod_{i=1}^n x^{a_i} ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- Phyre LCUE with YEBIS cause issues about GS
when LCUE enabled in phyreEngine when Yebis integrated and render there are two mainloopdraws in one ...
- 使用微信JSSDK自定义分享内容
微信在6.0.2.58版本以后开始使用新的api,在Android系统中不能用以前的代码来自定义分享内容了. 现在自定义内容的方法走的是公众号的一套流程 1获取access_token 2得到toke ...
- Linux软件安装方法小结(附:rpm详解)(转载)
在使用Linux系统的过程中,软件包的安装是避免不了的,在Linux下,软件安装程序的种类很多,安装方法也各式各样,(舒适性自然比不上windows :-))不过我们常见的软件包有两种: 1)含有软件 ...
- Tomcat server分端口部署web项目
<?xml version='1.0' encoding='utf-8'?> <Server port="8006" shutdown="SHUTDOW ...
- 使用tomcat7创建异步servlet
该篇文章翻译自:http://developerlife.com/tutorials/?p=1437 一.简介 Servlet API 3.0 之前,需要使用类似Comet的方式来实现创建异步的Ser ...
- POJ 1470 Closest Common Ancestors (最近公共祖先LCA 的离线算法Tarjan)
Tarjan算法的详细介绍,请戳: http://www.cnblogs.com/chenxiwenruo/p/3529533.html #include <iostream> #incl ...
- 利用PHP SOAP实现WEB SERVICE
php有两个扩展可以实现web service,一个是NuSoap,一个是php 官方的soap扩展,由于soap是官方的,所以我们这里以soap来实现web service.由于默认是没有打开soa ...
- UVA 11133 - Eigensequence DP
Given an increasing sequence of integers a1, a2, a3, . . . , ak, the E-transform produces a sequence ...
- UVA 10497 - Sweet Child Makes Trouble 高精度DP
Children are always sweet but they can sometimes make you feel bitter. In this problem, you will see ...
- hive-学习笔记
1.hive模糊搜索表 show tables like '*name*'; 2.查看表结构信息 desc formatted table_name; desc table_name; 3.查看 ...