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 ...
随机推荐
- DAY11-MYSQL数据操作
一 介绍 MySQL数据操作: DML ======================================================== 在MySQL管理软件中,可以通过SQL语句中的 ...
- Shell杀tomcat进程
一.killandclean.sh #!/bin/bash pid=($(ps -ef | grep tomcat | egrep -v grep | awk '{print $2}')) lengt ...
- spring读取classpath目录下的配置文件通过表达式去注入属性值.txt
spring读取配置文件: 1. spring加载配置文件: <context:property-placeholder location="classpath:config/syst ...
- java获取多个汉字的拼音首字母
本文属于http://java.chinaitlab.com/base/803353.html原创!!! public class PinYin2Abbreviation { // 简体中文的编码范围 ...
- [poj3348]Cows
题目大意:求凸包面积. 解题关键:模板题,叉积求面积. 这里的cmp函数需要调试一下,虽然也对,与普通的思考方式不同. #include<cstdio> #include<cstri ...
- 【总结整理】WebGIS学习-thinkGIS(二):关于level,比例尺scale,分辨率resolution
1.Level包含了一个resolution参数和一个scale参数 瓦片本身: 我们用arcgis切完图后,打开发布的服务或者打开config.xml配置文件,可以看到所切之图的相关配置.如图所示: ...
- HDU 4348(主席树 标记永久化)
题面一看就是裸的数据结构题,而且一看就知道是主席树... 一共四种操作:1:把区间[l, r]的数都加上d,并且更新时间.2:查询当前时间的区间和.3:查询历史时间的区间和.4:时光倒流到某个时间. ...
- Ros学习——导航
1.导航框架 在总体框架图中可以看到,move_base提供了ROS导航的配置.运行.交互接口,它主要包括两个部分: (1) 全局路径规划(global planner):根据给定的目标位置 ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-007归并排序(自下而上)
一. 1. 2. 3. 二.代码 package algorithms.mergesort22; import algorithms.util.StdIn; import algorithms.uti ...
- python 获取路径不同方法的比较
在软件中经常需要获取文件所在路径,方法有很多种( 例如 os.path.realpath(__file__), os.getcwd(), os.path.abspath(__file__), sys ...