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”三种中任意一种就输 ...
随机推荐
- BZOJ 3714: [PA2014]Kuglarz
Description 魔术师的桌子上有n个杯子排成一行,编号为1,2,-,n,其中某些杯子底下藏有一个小球,如果你准确地猜出是哪些杯子,你就可以获得奖品.花费c_ij元,魔术师就会告诉你杯子i,i+ ...
- A beginner’s introduction to Deep Learning
A beginner’s introduction to Deep Learning I am Samvita from the Business Team of HyperVerge. I join ...
- 百度Hi之CSRF蠕虫攻击
漏洞起因:百度是国内最大的中文搜索引擎.同时百度也提供了百度空间.百度贴吧等BLOG社区服务,拥有海量的用户群,号称全球最大中文社区. 80sec发现过百度产品一系列的安全漏洞,其中一些问题得到了有效 ...
- 数位DP之小小结
资料链接:http://wenku.baidu.com/view/9de41d51168884868662d623.html http://wenku.baidu.com/view/d2414ffe0 ...
- java多线程基础知识
1.ThrTest.java 继承Thread类方式 public class ThrTest extends Thread { private String name; public ThrTest ...
- ZOJ 2677 Oil Deal(最大生成树)
题意:破坏石油管道,现一直破坏各个管道所要付出的代价,问在有一定money并且要保证剩余的管道为生成树的情况下, 最多能破坏多少个管道,并将他们的编号从小到大输出来 思路:将边从大到小排序,构造生成树 ...
- POJ 2109
#include<iostream> #include<stdio.h> #include<math.h> using namespace std; int mai ...
- javascript 图片延迟加载
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- Sql Server总结
主键 主键就是数据行的唯一标识.不会重复的列,才能当主键.一个表可以没有主键,但是会非常难以处理,因此没有特殊理由表都要设定主键.主键有两种选用策略:业务主键和逻辑主键. 业务主键是使用有业务意义的 ...
- HDU 5596/BestCoder Round #66 (div.2) GTW likes math 签到
GTW likes math Memory Limit: 131072/131072 K (Java/Others) 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主 ...