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 ...
随机推荐
- UAC(User Agent Client) 和 UAS(User Agent Server)
SIP协议采用Client/Server模型.每一个请求(Request)触发服务器的一个操作:每个操作被称为方法(Method):每个请求除了指明具体方法外,还携带了一系列的头域(Header fi ...
- Solr搜索的排序打分规则探讨
使用Solr搭建搜索引擎很容易,但是如何制定合理的打分规则(boost)做排序却是一个很头痛的事情.Solr本身的排序打分规则是继承自Lucene的文本相关度的打分即boost,这一套算法对于通用的提 ...
- java中一些常用的英语
abstract (关键字 ) 抽象 ['.bstr.kt] access vt.访问,存取 ['.kses]'(n.入口,使用权) algorithm n.算法 ['.lg.rie ...
- 容器控件JPanel的使用
-----------------siwuxie095 工程名:TestUI 包名:com.siwuxie095.ui 类名:TestPanel.java 工程结构目录如下: 在默认窗体 JFrame ...
- __get(),__set(),__isset(),__unset()
__get(),__set(),__isset(),__unset() 在给不可访问属性赋值时,__set()会被调用读取不可访问属性的值时,__get()会被调用 当对不可访问属性调用isset() ...
- 面试题:hibernate第三天 一对多和多对多配置
1.1 一对多XML关系映射 1.1.1 客户配置文件: <?xml version="1.0" encoding="UTF-8"?> <!D ...
- 前端学习笔记2017.6.12 HTML的结构以及xhtml、html、xml的区别
HTML的结构 一个HTML文档可分为几个部分,如下图所示: DOCTYPE部分.head部分和body部分 DOCTYPE部分,这个很重要,可以理解为不同的DOCTYPE意味着不同的html标准,因 ...
- 两个进程之间的通讯——pipe 管道
在实际工作中,已经编辑好了NIPT_analysis的软件,该软件一般的输入文件是sam文件,但是为了集成进入测序仪器,需要直接从比对软件的标准输出中读取sam文件,省去了比对软件和NIPT_anal ...
- swing JCheckBox 更换复选框样式
Java Swing - 如何自定义JCheckBox复选标记图标 摘自 https://www.w3cschool.cn/java/codedemo-484050311.html import ja ...
- Entity Framework Tutorial Basics(15):Querying with EDM
Querying with EDM: We have created EDM, DbContext, and entity classes in the previous sections. Here ...