CodeForces - 359C-Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number t equals xa1 + a2 + ... + an. Now Simon wants to reduce the resulting fraction.
Help him, find the greatest common divisor of numbers s and t. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (109 + 7).
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
Examples
2 2
2 2
8
3 3
1 2 3
27
2 2
29 29
73741817
4 5
0 0 0 0
1
Note
In the first sample . Thus, the answer to the problem is 8.
In the second sample, . The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.
In the third sample the answer to the problem is 1073741824 mod 1000000007 = 73741817.
In the fourth sample . Thus, the answer to the problem is 1.
思路是主要的进制的思想
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#define mod 1000000007 const int maxn=1e5+;
typedef long long ll;
using namespace std;
ll quickpow(ll a,ll b)
{
ll ans=;
while(b)
{
if(b&)
ans=(ans*a)%mod;
b>>=;
a=(a*a)%mod;
}
return ans;
}
ll a[maxn];
int main()
{
ll n,x;
cin>>n>>x;
ll s=;
for(int t=;t<n;t++)
{
scanf("%lld",&a[t]);
s+=a[t];
}
for(int t=;t<n;t++)
{
a[t]=s-a[t];
}
ll ans,cnt=;
sort(a,a+n);
a[n]=-;
for(int t=;t<=n;t++)
{
if(a[t]!=a[t-])
{
if(cnt%x)
{
ans=a[t-];
break;
}
else
{
cnt/=x;
a[t-]++;
t--;
}
}
else
{
cnt++;
}
}
ll ss=min(s,ans);
cout<<quickpow(x,ss)<<endl;
return ;
}
CodeForces - 359C-Prime Number的更多相关文章
- CodeForce 359C Prime Number
Prime Number CodeForces - 359C Simon has a prime number x and an array of non-negative integers a1, ...
- Prime Number CodeForces - 359C (属于是数论)
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fracti ...
- Codeforces H. Prime Gift(折半枚举二分)
题目描述: Prime Gift time limit per test 3.5 seconds memory limit per test 256 megabytes input standard ...
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 每日一九度之 题目1040:Prime Number
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6732 解决:2738 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k- ...
- LintCode-Kth Prime Number.
Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. The eli ...
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- 10 001st prime number
这真是一个耗CPU的运算,怪不得现在因式分解和素数查找现在都用于加密运算. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13 ...
- CodeForces 432C Prime Swaps
Description You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your ...
- [LeetCode] Prime Number of Set Bits in Binary Representation 二进制表示中的非零位个数为质数
Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime ...
随机推荐
- 数据库访问优化漏斗法则- 四、减少数据库服务器CPU运算
数据库访问优化漏斗法则这个优化法则归纳为5个层次:1.减少数据访问次数(减少磁盘访问)2.返回更少数据(减少网络传输或磁盘访问)3.减少交互次数(减少网络传输)4.减少服务器CPU开销(减少CPU及内 ...
- dos 下bat命令
注:cmd下 help > result.txt assoc 显示或修改文件扩展名关联. attrib 显示或更改文件属性. break 设置或清除扩展式 ctrl+c 检查. bcded ...
- Android中SQLite查询date类型字段出现有返回但是为错误值的情况
出现该情况的原因是因为查询精度与数据库中存储精度不相同造成的,例如,查询精度为 YYYY-MM-DD 但是存储精度为 YYYY-MM-DD HH:MM:SS,就会出现该错误. 更改查询精度为YYYY- ...
- 卸载phonegap
npm uninstall cordova -gnpm uninstall phonegap -g
- Cocos2d-js 热更新学习笔记
转载至: http://blog.csdn.net/pt_xxj/article/details/68927705 为什么还要再写一篇关于cocos2d js热更新的笔记,最单纯的想法就是记录心得,另 ...
- opencv reshape函数说明
转自http://blog.csdn.net/yang6464158/article/details/20129991 reshape有两个参数: 其中,参数:cn为新的通道数,如果cn = 0,表示 ...
- 动态tab页
1.前台代码 <%-- builed by manage.aspx.cmt [ver:2015.25.26] at 2015-06-26 15:25:42 --%> <%@ Pag ...
- 什么是MTU,如何检测和设置路由器MTU值
最大传输单元(Maximum Transmission Unit,MTU)是指一种通信协议的某一层上面所能通过的最大数据包大小(以字节为单位).最大传输单元这个参数通常与通信接口有关(网络接口卡.串口 ...
- html相关标记的含义
HTML标记含义1.<html>...</html> :html 文档标记2.<head>...</head> :文档头标记3.<title> ...
- 《Effective Java》第4章 类和接口
第13条:使类和成员的可访问性最小化 第一规则很简单:尽可能地使每个类或者成员不被外界访问.换句话说.应该使用与你正在编写的软件的对应功能相一致的.尽可能最小的访问级别. 对于顶层的(非嵌套的)类和接 ...