http://codeforces.com/contest/359/problem/C

先求出分子的公因子,然后根据分子上会除以公因子会长生1,然后记录1的个数就可以。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200000
#define LL __int64
using namespace std; LL a[maxn];
LL n,x;
LL min1(LL s,LL d)
{
if(s>d)return d;
return s;
} LL pow_mod(LL a,LL p,LL m)//快速幂取模
{
if(p==) return ;
LL ans1=pow_mod(a,p/,m);
ans1=ans1*ans1%m;
if(p%==) ans1=ans1*a%m;
return ans1;
} int main()
{
while(scanf("%I64d%I64d",&n,&x)!=EOF)
{
LL sum=;
for(int i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
sum+=a[i];
}
LL ans=sum-a[n];//分子中最小公因子
LL c=a[n];
int t1=;//记录可以产生1的个数
int pos=n;
while(c>=)
{
while(a[pos]==c&&pos>=)
{
pos--;
t1++;
}
c--;
if(t1%x==)
{
ans++;
t1/=x;
}
else
break;
}
ans=min1(ans,sum);
printf("%I64d\n",pow_mod(x,ans,));
}
return ;
}

cf C. Prime Number的更多相关文章

  1. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  2. 每日一九度之 题目1040:Prime Number

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6732 解决:2738 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k- ...

  3. 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 ...

  4. 10 001st prime number

    这真是一个耗CPU的运算,怪不得现在因式分解和素数查找现在都用于加密运算. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13 ...

  5. [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 ...

  6. [Swift]LeetCode762. 二进制表示中质数个计算置位 | 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 ...

  7. 10_ for 练习 _ is Prime Number ?

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  8. 762. Prime Number of Set Bits in Binary Representation二进制中有质数个1的数量

    [抄题]: Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a ...

  9. LeetCode 762 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 ...

随机推荐

  1. 设计模式 ( 十七 ):Observer 观察者模式 -- 行为型

    1.概述 一些面向对象的编程方式,提供了一种构建对象间复杂网络互连的能力.当对象们连接在一起时,它们就可以相互提供服务和信息. 通常来说,当某个对象的状态发生改变时,你仍然需要对象之间能互相通信.但是 ...

  2. c# 实现文件拖入和拖出(拖拽)

    摘自:http://www.cnblogs.com/eaglet/archive/2009/01/06/1370149.html C# WinForm下一步一步实现文件的拖入和拖出 作者:Eaglet ...

  3. [LeetCode] 21. Merge Two Sorted Lists 解题思路

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  4. Linux之V4L2视频采集编程详解

     V4L2(Video For Linux Two) 是内核提供给应用程序访问音.视频驱动的统一接口. Linux系统中,视频设备被当作一个设备文件来看待,设备文件存放在 /dev目录下,完整路径的设 ...

  5. JDBC编程之优化

    1.创建 dbconfig.properties driver=com.mysql.jdbc.Driver dburl=jdbc\:mysql\://localhost\:3306/mytest us ...

  6. 高性能WEB开发(11) - flush让页面分块,逐步呈现

    高性能WEB开发(11) - flush让页面分块,逐步呈现 在处理比較耗时的请求的时候,我们总希望先让用户先看到部分内容,让用户知道系统正在进行处理,而不是无响应.一般大家在处理这样的情况,都使用a ...

  7. (step4.3.1) hdu 1010(Tempter of the Bone——DFS)

    题目大意:输入三个整数N,M,T.在接下来的N行.M列会有一系列的字符.其中S表示起点,D表示终点. .表示路 . X表示墙...问狗能有在T秒时到达D.如果能输出YES, 否则输出NO 解题思路:D ...

  8. C++指针数组和数组指针

    指针相关问题 using namespace std; int main(){ //a) 一个整型数( An integer) int a; //b) 一个指向整型数的指针( A pointer to ...

  9. HTML与CSS入门——第四章 理解层叠样式表

    知识点: 1.创建基本样式表的方法 2.使用样式类的方法 3.使用样式ID的方法 4.构建内部样式表和嵌入样式的方法 4.1 CSS工作原理: CSS:层叠样式表的缩写,是一种定义样式结构如字体.颜色 ...

  10. Jquery 使用JSOPN实例

    1.说明 dataType:返回的数据类型 jsonp:传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback) jsonpCallback:自定义的jsonp ...