CF/359/C. Prime Number
来源:互联网 发布:网络淘宝涮单是真的嘛 编辑:程序博客网 时间:2024/05/27 01:17
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).
2 22 2
8
3 31 2 3
27
2 229 29
73741817
4 50 0 0 0
1
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<stdio.h>#include<string.h>#include<map>#include<iostream>#include<algorithm>using namespace std;const int MOD=1000000007;int a[100010];map<long long ,int>m;long long quick_mul(long long num,long long t){ long long ans=1; long long pt=num%MOD; while(t) { if(t&1) ans=ans*pt%MOD; pt=pt*pt%MOD; t>>=1; } return ans;}int main(){ // freopen("in.txt","r",stdin); int n,k; while(~scanf("%d%d",&n,&k)) { m.clear(); long long sum=0; for(int i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; } for(int i=0;i<n;i++) { long long x=sum-a[i]; m[x]++; while(m[x]==k){ //k个 k^x 相加= 一个k^(x+1); m.erase(x); m[++x]++; } } long long ans=min(sum,m.begin()->first); //要注意分子可能比分母大的情况! 不然就一直wa 8 ans=quick_mul(k,ans); cout<<ans<<endl; } return 0;}
- CF/359/C. Prime Number
- cf 359c Prime Number
- CF 359C Prime Number(数论)
- CF 359C Prime Number 暴力
- Codeforces —— 359C Prime Number
- CF 251C Number Transformation
- Number Transformation CF 251C
- Codeforces 359C Prime Number (数学+快速幂)
- CodeForces 359C Prime Number 数学+快速幂
- Codeforces Round #209 C - Prime Number
- Codeforces 209 div2 C. Prime Number
- C. Prime Number----数论+快速幂
- CF 266 C. Number of Ways
- 【CF】466C Number of Ways 预处理
- CF 466C Number of Ways
- CF:Problem 385C - Bear and Prime Numbers 预处理DP
- CF C. Bear and Prime Numbers 筛选素数并计算
- 【数论】CF 385C Bear and Prime Numbers
- 【线段树(lazy)】poj 2777 Count Color
- linux下编译bochs-2.6.2
- 常用到的Web测试辅助工具
- android关于屏幕画图的一些度量单位及概念(sp,dp,px,dpi,density)
- Cocos2d-x 反复动画
- CF/359/C. Prime Number
- 【PHP自学笔记1】如何搭建配置PHP环境、云平台发布、第一个HelloWorld程序
- UVa:11624 Fire!
- IP摄像机
- 多线程笔试面试概念问答
- 如何将string转换为Date类型
- android串口通信实例分析
- BogoMips 提高
- UML 之 概述